microsoft / vscode-cpptools

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

Intellisense doesn't recognise inline variables from headers files #6833

Closed TerensTare closed 3 years ago

TerensTare commented 3 years ago

Type: LanguageService

Describe the bug

Steps to reproduce

1. Create a header file on the main directory with the following content. ```cpp // my_header.hpp #ifndef MY_HEADER #define MY_HEADER namespace my { inline struct tag_type {} tag; } #endif ```
2. Create a source file on the same dir with the following content. ```cpp // main.cpp #include "my_header.hpp" using my::tag; // error int main() { auto a = my::tag; // error } ```

Expected behavior I expected the Intellisense to suggest me my::tag when typing my::. Also I expected to see no error (I get: namespace "my" has no member "tag") as the variable exists. The example compiles fine with MSVC 14.28.29333,

Logs C/C++: Log Diagnostics ``` -------- Diagnostics - 1/22/2021, 10:47:20 AM Version: 1.2.0-insiders2 Current Configuration: { "name": "Win32", "includePath": [ "${workspaceFolder}/include", "${vcpkgRoot}/x64-windows/include" ], "defines": [ "TNT_BUILD", "TNT_PROFILING", "SOL_PRINT_ERRORS=1", "SOL_NO_EXCEPTIONS=1" ], "windowsSdkVersion": "10.0.19041.1", "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29333\\bin\\Hostx64\\x64\\cl.exe", "cStandard": "c17", "cppStandard": "c++20", "intelliSenseMode": "msvc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "path": [ "${workspaceFolder}/include", "${vcpkgRoot}/x64-windows/include", "${workspaceFolder}" ] }, "compilerArgs": [], "intelliSenseModeIsExplicit": true, "cStandardIsExplicit": true, "cppStandardIsExplicit": true, "compilerPathIsExplicit": true, "configurationProvider": "ms-vscode.cpptools" } Translation Unit Mappings: [ E:\thing\cpp\tnt\main.cpp ]: E:\THING\CPP\TNT\MAIN.CPP Translation Unit Configurations: [ E:\thing\cpp\tnt\main.cpp ]: Process ID: 12808 Memory Usage: 242 MB Compiler Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64\cl.exe Includes: E:\THING\CPP\TNT\INCLUDE C:\USERS\MY_USER\VCPKG\INSTALLED\X64-WINDOWS\INCLUDE C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\BUILDTOOLS\VC\TOOLS\MSVC\14.28.29333\INCLUDE C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT Defines: TNT_BUILD TNT_PROFILING SOL_PRINT_ERRORS=1 SOL_NO_EXCEPTIONS=1 Standard Version: ms_c++latest IntelliSense Mode: windows-msvc-x64 Total Memory Usage: 242 MB ------- Workspace parsing diagnostics ------- Number of folders and files enumerated: 12651 Number of files discovered (not excluded): 7353 ``` Language server ``` cpptools/didChangeCppProperties $/setTraceNotification cpptools/getCodeActions: file:///e%3A/thing/cpp/tnt/main.cpp (id: 982) cpptools/activeDocumentChange: file:///e%3A/thing/cpp/tnt/main.cpp cpptools/textEditorSelectionChange cpptools/getDocumentSymbols: file:///e%3A/thing/cpp/tnt/main.cpp (id: 983) cpptools/textEditorSelectionChange cpptools/getDocumentSymbols cpptools/getFoldingRanges: file:///e%3A/thing/cpp/tnt/main.cpp (id: 984) cpptools/getCodeActions: file:///e%3A/thing/cpp/tnt/main.cpp (id: 985) idle loop: reparsing the active document Checking for syntax errors: file:///e%3A/thing/cpp/tnt/main.cpp Queueing IntelliSense update for files in translation unit of: E:\THING\CPP\TNT\MAIN.CPP cpptools/finishUpdateSquiggles Error squiggle count: 41 Update IntelliSense time (sec): 0.327 cpptools/getSemanticTokens: file:///e%3A/thing/cpp/tnt/main.cpp (id: 986) cpptools/getFoldingRanges: file:///e%3A/thing/cpp/tnt/main.cpp (id: 987) cpptools/getCodeActions: file:///e%3A/thing/cpp/tnt/main.cpp (id: 988) cpptools/activeDocumentChange: file:///e%3A/thing/cpp/tnt/main.cpp cpptools/textEditorSelectionChange idle loop: reparsing the active document Checking for syntax errors: file:///e%3A/thing/cpp/tnt/main.cpp Queueing IntelliSense update for files in translation unit of: E:\THING\CPP\TNT\MAIN.CPP cpptools/finishUpdateSquiggles Error squiggle count: 41 Update IntelliSense time (sec): 0.306 cpptools/getSemanticTokens: file:///e%3A/thing/cpp/tnt/main.cpp (id: 989) cpptools/getFoldingRanges: file:///e%3A/thing/cpp/tnt/main.cpp (id: 990) cpptools/getCodeActions: file:///e%3A/thing/cpp/tnt/main.cpp (id: 991) cpptools/activeDocumentChange: file:///e%3A/thing/cpp/tnt/main.cpp cpptools/textEditorSelectionChange idle loop: reparsing the active document Checking for syntax errors: file:///e%3A/thing/cpp/tnt/main.cpp Queueing IntelliSense update for files in translation unit of: E:\THING\CPP\TNT\MAIN.CPP cpptools/finishUpdateSquiggles Error squiggle count: 41 Update IntelliSense time (sec): 0.344 cpptools/getSemanticTokens: file:///e%3A/thing/cpp/tnt/main.cpp (id: 992) cpptools/getFoldingRanges: file:///e%3A/thing/cpp/tnt/main.cpp (id: 993) cpptools/getCodeActions: file:///e%3A/thing/cpp/tnt/main.cpp (id: 994) ```
Colengms commented 3 years ago

Hi @TerensTare . I pasted the code you provided into a header and cpp source file, and am not able to repro the issue.

image

Is it possible there is some other issue here, such as another header that has already defined MY_HEADER?

Can you provide a simple repro in the form of a GitHub repo we can clone?

TerensTare commented 3 years ago

Hi @Colengms . Thanks for the response. I checked the include guards and there is no #define collision. I was getting the error on this repo, specifically on main.cpp

TerensTare commented 3 years ago

I think I owe a deep apology to everybody included in this. The problem came from a template-d struct from the project. I recently deleted a member variable from that struct, and deleted the closing brace of the struct. This apparently lead to the series of errors, as they disappeared soon as I added the missing }. Thank you Colenmgs (again).