Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::initializer_list does not contain the expected constructor #12275

Open
Unturned3 opened this issue May 3, 2024 · 7 comments
Open

std::initializer_list does not contain the expected constructor #12275

Unturned3 opened this issue May 3, 2024 · 7 comments
Assignees
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state

Comments

@Unturned3
Copy link

Unturned3 commented May 3, 2024

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)".

Screenshot 2024-05-03 at 18 09 20

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

@sean-mcmanus
Copy link
Collaborator

@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?

@sean-mcmanus sean-mcmanus self-assigned this May 3, 2024
@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state Feature: Configuration An issue related to configuring the extension or IntelliSense labels May 3, 2024
@Unturned3
Copy link
Author

Unturned3 commented May 3, 2024

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.

@sean-mcmanus
Copy link
Collaborator

@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.

@Unturned3
Copy link
Author

Unturned3 commented May 4, 2024

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.

@MinetaS
Copy link

MinetaS commented May 5, 2024

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

@browntarik browntarik self-assigned this May 6, 2024
@browntarik
Copy link
Contributor

@Unturned3 @MinetaS Does the issue persist when changing your IntelliSense Mode to *-clang-x86?

@MinetaS
Copy link

MinetaS commented May 9, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service more info needed The issue report is not actionable in its current state
Projects
None yet
Development

No branches or pull requests

4 participants