microsoft / microsoft/vscode-cpptools
Intellisense expects an indentifier when using C preprocessor
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Bug type: Language Service
In a project I am working on (Varnish Cache), there is commonly used preprocessor pattern where indentifier values are put into a seperate header value and included into the actual definition (this lets you get the indentifier later as a string value in code and other things). Intellisense seems to not like this pattern, reporting errors in both the C file and the H file:
expected an identifier C/C++ (40)
Here is a reproducible test case:
// test.c
enum test
{
#define TM(name) t_ ## name,
#include "test.h"
};
int main()
{
enum test t = t_two;
return (t == t_one);
}
// test.h
TM(one)
TM(two)
#undef TM
The Intellisense errors are reported at the end of the enum definition in the C file and at the end of the H file. This compiles fine on most every C compiler I have used.
VS Code version: Code 1.63.1 (fe719cd3e5825bf14e14182fddeb88ee8daf044f, 2021-12-14T02:02:02.183Z)
OS version: Linux x64 5.11.0-41-generic snap
Restricted Mode: No
C/C++: Log Diagnostics
-------- Diagnostics - 12/14/2021, 2:11:49 PM
Version: 1.8.0-insiders2
Current Configuration:
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [],
"intelliSenseModeIsExplicit": false,
"cStandardIsExplicit": false,
"cppStandardIsExplicit": false,
"mergeConfigurations": false,
"compilerPathIsExplicit": false,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ /home/reza/Code/test/vstest/test.c ]:
/home/reza/Code/test/vstest/test.h *
/home/reza/Code/test/vstest/test.c
Translation Unit Configurations:
[ /home/reza/Code/test/vstest/test.c ]:
Process ID: 108590
Memory Usage: 12 MB
Compiler Path: /usr/bin/gcc
Includes:
/usr/lib/gcc/x86_64-linux-gnu/9/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=90300
Total Memory Usage: 12 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 2509
System Info
| Item | Value |
|---|---|
| CPUs | 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 x 1800) |
| GPU Status | 2d_canvas: unavailable_software gpu_compositing: disabled_software multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: disabled_off rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: unavailable_software webgl2: unavailable_software |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 15.37GB (8.31GB free) |
| Process Argv | --no-sandbox --force-user-env --unity-launch --crash-reporter-id f6d4888a-1739-431b-aa18-f552c065d1ff |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | ubuntu |
| XDG_CURRENT_DESKTOP | Unity |
| XDG_SESSION_DESKTOP | ubuntu |
| XDG_SESSION_TYPE | x11 |
Extensions (3)
| Extension | Author (truncated) | Version |
|---|---|---|
| remote-ssh | ms- | 0.70.0 |
| cpptools | ms- | 1.8.0-insiders2 |
| cpptools-extension-pack | ms- | 1.1.0 |
(1 theme extensions excluded)
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 diagnostic with the issue's test.c and test.h files using the C/C++ IntelliSense configuration described in the report. Start by tracing how the language service processes the enum, macro, and included header; done means the valid preprocessor pattern no longer produces the reported errors in either file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100