microsoft / vscode-cpptools

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

IntelliSense under clang-x64 doesn't support Microsoft integer suffixes #11585

Open whypet opened 1 year ago

whypet commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: When using IntelliSense mode clang-x64, IntelliSense doesn't recognize Microsoft integer suffixes (which are used in the Windows SDK), however it works when using IntelliSense mode msvc-x64. Despite that, these suffixes compile on Clang.

Steps to reproduce:

  1. Create a main.c file containing:
    int main(void) { return 0i32; }

    or

    // the Clang header has '#include_next <limits.h>' which includes limits.h
    // from the Windows SDK, in turn using these integer suffixes
    #include <limits.h>
    int main(void) { return _I32_MAX; }
  2. Set IntelliSense mode to clang-x64 in c_cpp_properties.json
  3. Hover over integer constant
  4. See error squiggle "extra text after expected end of number"
  5. Compile using this command line: clang main.c -Weverything -o main.exe
  6. No warnings or errors generated

Expected behavior: Shouldn't display any error, or perhaps an error about compiler portability that explicitly states it's a Microsoft extension.

Configuration and Logs

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "compilerPath": "C:/Program Files/LLVM/bin/clang.exe",
            "intelliSenseMode": "clang-x64",
            "configurationProvider": "ms-vscode.cpptools"
        }
    ],
    "version": 4
}

Logs:

-------- Diagnostics - 10/25/2023, 3:26:01 PM
Version: 1.17.5
Current Configuration:
{
    "name": "Win32",
    "compilerPath": "C:/Program Files/LLVM/bin/clang.exe",
    "intelliSenseMode": "clang-x64",
    "configurationProvider": "ms-vscode.cpptools",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": false,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "C:/Program Files/LLVM/bin/clang.exe",
    "configurationProviderInCppPropertiesJson": "ms-vscode.cpptools",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.17.5.0
Translation Unit Mappings:
[ E:\vscode-cpptools bug\main.c ]:
    E:\vscode-cpptools bug\main.c
Translation Unit Configurations:
[ E:\vscode-cpptools bug\main.c ]:
    Process ID: 1268
    Memory Usage: 54 MB
    Compiler Path: C:\Program Files\LLVM\bin\clang.exe
    Includes:
        C:\Program Files\LLVM\lib\clang\17\include
        C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.37.32820\include
        C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.37.32820\atlmfc\include
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt
        C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt
    Standard Version: c17
    IntelliSense Mode: windows-clang-x64
    Other Flags:
        --clang
        --clang_version=170002
        --ms_compatibility
Total Memory Usage: 54 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 5486

Other Extensions

Same behavior when the only enabled extension is C/C++.

Additional context

image image image

Colengms commented 1 year ago

Hi @whypet . Thanks for reporting this. I've opened an internal bug against VS, as this issue also occurs in VS and is in IntelliSense code that is shared with VS. (ID 1908009).

Colengms commented 1 year ago

@whypet Also, FYI, this line in your configuration appears to be invalid:

"configurationProvider": "ms-vscode.cpptools"

This field is for specifying the ID of a custom configuration provider, such as CMake Tools and Makefile Tools. I don't think having an incorrect value here is going to hurt, but I'd suggest removing it, just in case.

whypet commented 1 year ago

Hey, thanks for the heads-up, I'll remove that line from my configurations. I remember thinking it was needed because I was using CMake Tools and ended up having issues with it not giving IntelliSense some information like include directories, so I tried to do it manually.

bobbrow commented 1 year ago

CMake Tools will only provide information for headers if you list the headers in your add_executable/add_library invocations. Otherwise, you can get the information transitively by opening a source file that includes that header.

whypet commented 1 year ago

I see, thanks. Maybe I was facing these issues because I use target_sources to list all source and header files instead but I'm not sure, I'm a bit new to CMake as a whole.