microsoft / microsoft/vscode-cpptools
[IntelliSense C] The "defined" operator is not correctly interpreted by #if
Open
Nobody has claimed this yet.
bug
Feature: Configuration
Language Service
more votes needed
Visual Studio
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and Version: Windows 10 Entreprise 22H2
- VS Code Version: 1.86.1
- C/C++ Extension Version: 1.18.5
Bug Summary and Steps to Reproduce
The VSCode editor doesn't seem to interpret #if statements correctly when using the special operator "defined"
Example with the following code:
#define A_DEFINED_VARIABLE 1
#define CHECK_A_DEFINED_VARIABLE (defined(A_DEFINED_VARIABLE))
#if (defined(A_DEFINED_VARIABLE))
static int MyVar1 = 1;
#endif
#if CHECK_A_DEFINED_VARIABLE
static int MyVar2 = 2;
#endif
int main()
{
return MyVar1 + MyVar2;
}
IntelliSense considers that MyVar1 is defined, but not MyVar2.
Configuration and Logs
-------- Diagnostics - 2/13/2024, 2:50:33 PM
Version: 1.18.5
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"compilerPathInCppPropertiesJson": "cl.exe",
"intelliSenseModeIsExplicit": false,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": false,
"mergeConfigurations": false,
"compilerPathIsExplicit": false,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
cpptools version (native): 1.18.3.0
Translation Unit Mappings:
[ C:\Data\Tmp\test.c ]:
C:\Data\Tmp\test.c
Translation Unit Configurations:
[ C:\Data\Tmp\test.c ]:
Process ID: 26476
Memory Usage: 49 MB
Compiler Path: C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\bin\Hostx64\x64\cl.exe
Includes:
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\include
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\atlmfc\include
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\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\winrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: ms_c17
IntelliSense Mode: windows-msvc-x64
Total Memory Usage: 49 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 5027
Other Extensions
No response
Additional context
No response
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
Start by reproducing the issue with the C snippet in the report using the listed VS Code and C/C++ extension versions, then inspect IntelliSense preprocessing of defined inside a macro used by #if. Done means MyVar2 is recognized consistently with MyVar1 when CHECK_A_DEFINED_VARIABLE expands to the defined expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100