std::initializer_list does not contain the expected constructor
Type: Bug
Create the following .cpp file:
#include <vector>
int main()
{
std::vector<int> v {1, 2, 3};
return 0;
}
A red error squiggle will appear before the vector's uniform initialization list, with the message "the definition of std::initializer_list does not contain the expected constructor C/C++(2348)".
clang version:
$ clang -v
Homebrew clang version 18.1.4
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/local/opt/llvm/bin/clang",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
Extension version: 1.20.4 VS Code version: Code 1.88.1 (e170252f762678dec6ca2cc69aba1570769a5d39, 2024-04-10T17:42:52.765Z) OS version: Darwin x64 23.3.0 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz (8 x 2000) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled |
| Load (avg) | 3, 4, 3 |
| Memory (System) | 16.00GB (2.14GB free) |
| Process Argv | --crash-reporter-id 7575e86b-e434-484d-8645-89363df807c7 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
ccp1r6:30993540
dsvsc020:30976470
pythonait:31006305
chatpanelt:31018789
dsvsc021:30996838
0ee40948:31013168
pythoncenvpt:31022790
a69g1124:31038041
dwnewjupytercf:31035177
@Unturned3 I don't repro the issue with the latest Apple clang (you're using the newer LLVM non-Apple clang though). Can you run the C/C++: Log Diagnostics command after opening the source file?
Hmm.. strange. I replaced /usr/local/opt/llvm/bin/clang with /usr/bin/clang for compilerPath (i.e. to use Apple's clang), and the issue disappeared. Why does this happen with Homebrew's latest clang though? What does that error message even mean?
Anyways, here's the C/C++: Log Diagonistics output:
-------- Diagnostics - 5/3/2024, 11:53:05 PM
Version: 1.20.4
Current Configuration:
{
"name": "Mac",
"includePath": [
"/Users/richard/Desktop/T2/**"
],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/local/opt/llvm/bin/clang",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerPathInCppPropertiesJson": "/usr/local/opt/llvm/bin/clang",
"mergeConfigurations": false,
"browse": {
"path": [
"/Users/richard/Desktop/T2/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
cpptools version (native): 1.20.4.0
No active translation units.
@Unturned3 I'm not sure. I know a similar error can occur if c++03 is used. Are you able to compile/link? Have you tried changing it to /usr/local/opt/llvm/bin/clang++? If you use go to def on either the <vector> or std::vector and looked for the constructor taking an initializer list it might show as disabled due to some defines.
Yes, I am able to compile & link with the Homebrew clang just fine. No errors/warnings. I tried setting the compilerPath to /usr/local/opt/llvm/bin/clang++ but the error persisted. I did check the <vector> header, but unfortunately my C++ knowledge is nowhere good enough for me to understand the mess in there.
This happens on Windows with msys clang 18.1.3 as well. Apparently, the error appears only when <initializer_list> is included before <vector>. Including <initializer_list> after <vector> does not have the problem.
To reproduce, create an empty workspace and write a simple C++ code:
// The error only appears if initializer_list is included before vector
#include <initializer_list>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
return 0;
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "C:\\\\msys64\\\\clang64\\\\bin\\\\x86_64-w64-mingw32-clang++.exe",
"intelliSenseMode": "windows-clang-x64",
"cStandard": "c17",
"cppStandard": "c++17",
"compilerArgs": [
"--std=c++17"
]
}
],
"version": 4
}
C/C++: Log Diagnostics:
-------- Diagnostics - 5/6/2024, 2:48:50 AM
Version: 1.20.4
Current Configuration:
{
"name": "Win32",
"includePath": [
"c:/Users/skdty/repos/test/**"
],
"defines": [],
"compilerPath": "C:\\\\msys64\\\\clang64\\\\bin\\\\x86_64-w64-mingw32-clang++.exe",
"intelliSenseMode": "windows-clang-x64",
"cStandard": "c17",
"cppStandard": "c++17",
"compilerArgs": [
"--std=c++17"
],
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerPathInCppPropertiesJson": "C:\\\\msys64\\\\clang64\\\\bin\\\\x86_64-w64-mingw32-clang++.exe",
"windowsSdkVersion": "10.0.22621.0",
"mergeConfigurations": false,
"browse": {
"path": [
"c:/Users/skdty/repos/test/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
cpptools version (native): 1.20.4.0
Translation Unit Mappings:
[ C:\Users\skdty\repos\test\test.cc - source TU]:
Translation Unit Configurations:
[ C:\Users\skdty\repos\test\test.cc ]:
Process ID: 20808
Memory Usage: 206 MB
Compiler Path: C:\msys64\clang64\bin\x86_64-w64-mingw32-clang++.exe
Includes:
C:\msys64\clang64\include\c++\v1
C:\msys64\clang64\lib\clang\18\include
C:\msys64\clang64\include
Standard Version: c++17
IntelliSense Mode: windows-clang-x64
Other Flags:
--clang
--clang_version=180103
Total Memory Usage: 206 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 6035
@Unturned3 @MinetaS Does the issue persist when changing your IntelliSense Mode to *-clang-x86?
@browntarik Yes, for windows-clang-x86 the issue persists. Along with the compiler path set to C:\msys64\clang32\bin\i686-w64-mingw32-clang++.exe.
I also have the same issue after updating my homebrew clangd to 18.1.6. Perhaps the cpptools extension does not recognize the updated header files, and treated/parsed the initializer list class as a normal class as opposed to a language supported and defined standard, which ultimately resulted in it not being able to find a suitable constructor?
Either way I really hope this gets updated/fixed soon by the team™
@MinetaS I am having trouble installing your compiler with a version of 18.x, could you walk me through some steps on how to acquire your compiler?
We are currently out of date with the version numbers of compilers that our IntelliSense supports, and those numbers will be updated but being able to get a clang compiler with the correct version will help with testing.
@browntarik Sorry for the late response. Somehow I unsubscribed this issue by mistake.
It's the official clang/llvm package from msys2. https://packages.msys2.org/package/mingw-w64-x86_64-clang
pacman -S mingw-w64-x86_64-clang
in msys2 terminal will install it. The compiler path is mentioned in my previous comment above.
Thanks for the information, we have been able to reproduce this bug. This issue has been reported to our internal team (VS: 2171136). Please follow this issue for more updates on when it has been fixed.
I'm suddenly seeing this issue on MacOS Sonoma 14.6.1 after a recent XCode developer tools update. Clang is:
$ clang++ -v
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: x86_64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ xcode-select -v
xcode-select version 2408.
Encountering same issue with below vector part from code after update my mac to Sequoia 15.0. header vector and initilizer_list are at the top of code.
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
vec<str> cmds = {
"prev",
"next",
"next"
};
I'm getting the same issue that smwkbgmn after having updated my Mac to Sequoia 15.0.
Bumping this.
After Mac 15.0 Sequoia update, I also got the definition of std::initializer_list does not contain the expected constructorC/C++(2348) even for a simple std::vector<int> v {1, 2, 3};. 😢
-
Apple clang version 16.0.0 -
xcode-select version 2409 -
code --versiongives1.93.1