microsoft / vscode-cpptools

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

__has_attribute(X) bad evaluation #10484

Open brvtalcake opened 1 year ago

brvtalcake commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: I'm working on a C project. I wrote something like this (actually not exactly like this, but I tried to rewrite it with the same conditionals) :

#if defined(__has_attribute) 
    #define ATTRIBUTE_CHECKING 1
#endif

#if ATTRIBUTE_CHECKING && __has_attribute(copy)
    #define ATTRIBUTE_COPY 1
#else 
    #error "Attribute copy not available"
#endif

The problem is that I configured Intellisense with linux-gcc-x64 with gcc (12.2.0), and the condition

ATTRIBUTE_CHECKING && __has_attribute(copy)

is considered false when it's supposed to be true. I made this simple test, in the same workspace, with the same settings, ... :

#include <stdio.h>
int main()
{
printf("%d\n", __has_attribute(copy));
return 0;
}

and it printed "1".

I also tried with attribute access, and the same issue appears.

Steps to reproduce:

  1. Just copy the macros and the main function and you'll see

Expected behavior: I think it's supposed to be true considering my config.

NOTE For the "logs from the language server logging", I deleted the macros detailed above and ctrl+z' them, then copied the result into the proper section, since it wasn't enabled before.

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/axel/Documents/programmation/c/FManC/test/third_party/"
            ],
            "defines": [],
            "compilerPath": "/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++23",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerArgs": [],
            "mergeConfigurations": false
        }
    ],
    "version": 4
}

C/C++: Log Diagnostics

-------- Diagnostics - 2/7/2023, 9:15:42 PM Version: 1.13.9 Current Configuration:

{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**",
        "/home/axel/Documents/programmation/c/FManC/test/third_party/"
    ],
    "defines": [],
    "compilerPath": "/bin/gcc",
    "cStandard": "gnu17",
    "cppStandard": "gnu++23",
    "intelliSenseMode": "linux-gcc-x64",
    "compilerArgs": [],
    "mergeConfigurations": false,
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true
}

Translation Unit Mappings:

[ /home/axel/Documents/programmation/c/FManC/test.c ]:
    /home/axel/Documents/programmation/c/FManC/test.c
[ /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h ]:
    /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
    /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h *

Translation Unit Configurations:

[ /home/axel/Documents/programmation/c/FManC/test.c ]:
    Process ID: 41594
    Memory Usage: 107 MB
    Compiler Path: /bin/gcc
    Includes:
        /home/axel/Documents/programmation/c/FManC/test/third_party
        /usr/include/c++/12
        /usr/include/x86_64-linux-gnu/c++/12
        /usr/include/c++/12/backward
        /usr/lib/gcc/x86_64-linux-gnu/12/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++23
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=120200
[ /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h ]:
    Process ID: 42694
    Memory Usage: 107 MB
    Compiler Path: /bin/gcc
    Includes:
        /home/axel/Documents/programmation/c/FManC/test/third_party
        /usr/lib/gcc/x86_64-linux-gnu/12/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --gcc
        --gnu_version=120200
        --header_only_fallback
Total Memory Usage: 215 MB

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

Logs from the language server logging

loggingLevel: Debug
loggingLevel has changed to: Debug
cpptools/didChangeCppProperties
$/setTrace
cpptools/didChangeSettings
Enhanced Colorization is enabled.
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
$/setTrace
cpptools/didChangeSettings
Enhanced Colorization is enabled.
Autocomplete is enabled.
Error squiggles are enabled.
Hover is enabled.
IntelliSense Engine = default.
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13161)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13162)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13163)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13164)
idle loop: reparsing the active document
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Error squiggle count: 0
Update IntelliSense time (sec): 0.254
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13165)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13166)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_platform.h (id: 13167)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13168)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13169)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13170)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13171)
idle loop: reparsing the active document
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 0.252
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13172)
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13173)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13174)
cpptools/textEditorSelectionChange
textDocument/documentHighlight: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13175)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13176)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13177)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13178)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13179)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13180)
cpptools/textEditorSelectionChange
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13181)
textDocument/didChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13182)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13183)
cpptools/getDocumentSymbols: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13184)
cpptools/getDocumentSymbols
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13185)
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
  tag parsing file: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 3
Update IntelliSense time (sec): 2.252
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13186)
textDocument/didChange: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13187)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13188)
cpptools/getSemanticTokens: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13189)
cpptools/getDocumentSymbols: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13190)
cpptools/getDocumentSymbols
cpptools/getInlayHints: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13191)
Checking for syntax errors: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
  tag parsing file: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
Queueing IntelliSense update for files in translation unit of: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h
sending 1 changes to server
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 2.252
cpptools/getFoldingRanges: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13192)
cpptools/getCodeActions: /home/axel/Documents/programmation/c/FManC/src/general/preprocessor/FMC_attributes.h (id: 13193)

Other Extensions

No response

Additional context

Here are the kind of macros I originally had

image image

As you can see it seems like there's no attribute access.

The simple test

image

browntarik commented 1 year ago

Thank you for submitting this issue! We have filed a bug with the Visual Studio team (1744911) and a fix should be made soon. This GitHub issue will track the progress of the fix.

xclaesse commented 1 year ago

Any progress on this? GLib uses __has_attribute(cleanup) to defined g_autoptr() macro. But since intellisense thinks that __has_attribute(cleanup) is false, all those macros are not defined and reported as error in code using it.