microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.46k stars 1.53k forks source link

[OSX] Multiple identifiers are undifened plus other erros while files compile okay #5551

Closed Xiaohong-Deng closed 4 years ago

Xiaohong-Deng commented 4 years ago

Type: LanguageService

Describe the bug

In the "Problems" panel, 72 errors are thrown while the cpp file compiles okay in terminal (depends on the specific complier, some requires minor changes, e.g., 7 variable-sized object errors which are allowed in some compilers). The issue is similar to #743. "C_Cpp.intelliSenseEngine":"Tag Parser" stops linting completely.

Steps to reproduce

My working example is this .cpp file and this .h file. The repo is the single project in VSCode.

My c_cpp_properties.json looks like the following

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/tr1",
                "/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/gcc/x86_64-apple-darwin17.3.0/7.3.0/include/ssp",
                "/usr/local/Cellar/postgresql/10.1/include/server/common",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
                "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0",
                "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/x86_64-apple-darwin17.3.0"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "browse": {
                "path": []
            },
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x86"
        }
    ],
    "version": 4
}

The result can be seen in the "Problems" panel. It can't recognize make_tuple, tie, unordered_map, memcpy and memset while pressing F12 leads to correct definitions.

Expected behavior

This is an OSX specific issue because on Ubuntu 18.04, with

"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x86"

The errors appear in the "Problems" panel are 7 variable-sized object may not be initialized which are consistent with the error message generated by clang++ -g -O2 -std=c++11 -stdlib=libc++ local_search.cpp -o ls.out in OSX terminal.

Logs ``` -------- Diagnostics - 5/22/2020, 9:23:57 AM Version: 0.28.1 Current Configuration: { "name": "Mac", "includePath": [ "${workspaceFolder}/**", "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/tr1", "/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/gcc/x86_64-apple-darwin17.3.0/7.3.0/include/ssp", "/usr/local/Cellar/postgresql/10.1/include/server/common", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include", "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0", "/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/x86_64-apple-darwin17.3.0" ], "defines": [], "macFrameworkPath": [], "browse": { "path": [], "limitSymbolsToIncludedHeaders": true }, "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++14", "intelliSenseMode": "clang-x86", "compilerArgs": [] } Memory Usage: 106 MB Compiler Path: /usr/bin/clang Includes: /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/tr1 /usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/gcc/x86_64-apple-darwin17.3.0/7.3.0/include/ssp /usr/local/Cellar/postgresql/10.1/include/server/common /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0 /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/x86_64-apple-darwin17.3.0 /usr/local/include /Library/Developer/CommandLineTools/usr/include/c++/v1 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include /Library/Developer/CommandLineTools/usr/include Frameworks: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks Standard Version: c++14 IntelliSense Mode: clang-x86 Other Flags: --clang --clang_version=110003 Total Memory Usage: 106 MB ```

Screenshots

截屏2020-05-22 上午9 42 06

Additional context

sean-mcmanus commented 4 years ago

You should remove the system include paths from your includePath and instead set the compilerPath. Are you trying to compile with gcc 7.3 or clang?

Xiaohong-Deng commented 4 years ago

@sean-mcmanus You are right. I trimmed includePath down to "${workspaceFolder}/**". The other paths were added while I was trying to make it work with gcc and they did eliminate some header file missing errors. Thank you.