microsoft / microsoft/vscode-cpptools
False positive error on C nested structs
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Type: Bug
VSCode claims that the assignment to foo.bar below is an error "a value of type "struct Bar" cannot be assigned to an entity of type "struct Bar" C/C++(513)"
The code compiles cleanly both with gcc and clang (with -Wall -Wextra in both cases). I believe it is ISO C compliant, although a fairly uncommon usage. (In C nested, named, structs become part of the global namespace, which is different from C++.)
// C not C++.
struct Foo {
struct Bar {
int x;
} bar;
};
int main(void)
{
struct Foo foo;
foo.bar = (struct Bar) {0}; // Incorrectly marked as an error by VSCode.
return foo.bar.x;
}
Extension version: 1.22.11
VS Code version: Code 1.95.3 (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z)
OS version: Linux x64 6.11.7-300.fc41.x86_64
Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 x 3700) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off webnn: disabled_off |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 62.48GB (36.96GB free) |
| Process Argv | --crash-reporter-id 73c5a75d-b680-4906-94d8-412f0182e453 |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | mate |
| XDG_CURRENT_DESKTOP | MATE |
| XDG_SESSION_DESKTOP | mate |
| XDG_SESSION_TYPE | x11 |
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
2i9eh265:30646982
962ge761:30959799
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
724cj586:31013169
dvdeprecation:31068756
dwnewjupytercf:31046870
2f103344:31071589
nativerepl2:31139839
pythonrstrctxt:31112756
cf971741:31144450
iacca1:31171482
notype1cf:31157160
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
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 with the minimal nested-struct C reproduction in the issue and inspect how the C/C++ extension analyzes the assignment to foo.bar. Compare the extension's diagnostic with GCC and Clang results. Done means valid ISO C produces no false type-mismatch error in VS Code, with regression coverage added if the project provides a suitable test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100