Vscode-cpptools: The definition of std::initializer_list does not contain the expected constructor

Created on 28 Oct 2017  Â·  9Comments  Â·  Source: microsoft/vscode-cpptools


image

Getting an error when using initializer lists: the definition of std::initializer_list does not contain the expected constructor.

Example:

#include <vector>
#include <iostream>

int main() {
    std::vector<int> testVector{1, 2, 3};
    for (auto n : testVector) {
        std::cout << n << "\n";
    }
}

Program compiles and runs fine.

I'm using the recommended WSL configuration from the docs as well as one for the non-beta version, issue happens for both.

{
    "configurations": [
        {
            "name": "WSL Beta",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/lxss/rootfs/usr/include/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/c++/5/backward",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/lxss/rootfs/usr/local/include",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/lxss/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/lxss/rootfs/usr/include/c++/5",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/lxss/rootfs/usr/local/include",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/lxss/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "WSL",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5/backward",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 3
}

Extension version is 0.14.0, VS Code version is 1.17.2

Language Service bug

Most helpful comment

@bobbrow @1iuyzh This problem in MinGW-W64 can be solved by adding __SIZE_TYPE__=long long unsigned int in the "c_cpp_properties.json" file.

All 9 comments

I also meet similar problem :
1

#include <iostream>
#include <list>
#include <string>
#include <vector>

using std::cin; using std::cout; using std::endl;
using std::list;
using std::string;
using std::vector;

int main() {
    list<const char *> l1 = {"Milton", "Shakespeare", "Austen"};
    vector<string> v1;
    v1.assign(l1.begin(), l1.end());
    for (auto i : v1) cout << i << ' ';
    cout << endl;
    return 0;
}

The program compiles and runs normally
I'm using mingw-w64 on Windows
I havae modified "c_cpp_properties.json" according to c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++",
                "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/x86_64-w64-mingw32",
                "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include/c++/backward",
                "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include",
                "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include-fixed",
                "E:/mingw-w64/mingw64/x86_64-w64-mingw32/include",
                "E:/mingw-w64/mingw64/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include",
                    "E:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include-fixed",
                    "E:/mingw-w64/mingw64/x86_64-w64-mingw32/include",
                    "E:/mingw-w64/mingw64/include"
                ]
            }
        }
    ],
    "version": 3
}

I'm not able to repro this on Linux/Windows. @bobbrow Are you able to repro this? Maybe it requires a certain library version.

It's MinGW 6.3. I have a repro.

We need to redefine "unsigned long" as 8 bytes on Windows when clang-x64 intelliSenseMode is being used. We also need the inverse when msvc-x64 is used on Mac. I have a bug on this already, but I don't remember whether I linked it to GitHub or not. The incorrect representation of size_t causes the compiler to fail to find some std methods.

@bobbrow @1iuyzh This problem in MinGW-W64 can be solved by adding __SIZE_TYPE__=long long unsigned int in the "c_cpp_properties.json" file.

Happens for me with WSL on Windows 10 Creators Update, VSCode 1.21.

I have Clang 7.0 installed on Ubuntu but can't get cpptools to choose it over the default clang++-3. I guessed that was part of the issue--old Clang not supporting some feature--but that seems implausible.

In the upcoming release you will be able to set the path to your compiler and we'll get the default include path and defines from it.

@bobbrow @1iuyzh This problem in MinGW-W64 can be solved by adding __SIZE_TYPE__=long long unsigned int in the "c_cpp_properties.json" file.

well,thank you for your answer. it works on my machine.

This looks to have been addressed. Please let us know if this is still an issue.

Was this page helpful?
0 / 5 - 0 ratings