microsoft / microsoft/vscode-cpptools
__has_attribute(X) bad evaluation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and Version: Ubuntu 22.10
- VS Code Version: e2816fe7 (snap store)
- C/C++ Extension Version: v1.13.9
- If using SSH remote, specify OS of remote machine: none
- C standard : gnu17
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:
- 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


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

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the condition in test.c using the c_cpp_properties.json configuration and compare IntelliSense with GCC's result. Inspect processing for FMC_attributes.h and FMC_platform.h, then verify that __has_attribute(copy) evaluates consistently in the reported conditional and that the false-condition diagnostic no longer appears.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, vscode
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100