microsoft / microsoft/vscode-cpptools
Create Declaration / Definition with wrong name space (and possibly scope) in C
Open
Nobody has claimed this yet.
bug
Feature: Create Declaration or Definition
Language Service
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 11 Pro 22H2
- VS Code Version: 1.79.2
- C/C++ Extension Version: 1.16.3
Bug Summary and Steps to Reproduce
Bug Summary:
Steps to reproduce:
- Create a new C source file, as "main.c"
- Add the definition of some
staticfunctions; create some with astructtype parameter - Position the cursor on a function name
- Recall with ctrl+shift+P the function "C/C++: Create Declaration/Definition"
- A file named "main.h" is opened and the prototype added
- Note that
- even if the function is declared as
statica prototype is created in another file/header ("main.h") - only if you have the precedent function already declared in "main.c" then the prototype goes to "main.c" as well (expected behavior)
- if your function has
structparameters thestructtype specifier is removed, e.g.static int foo(struct MyStruct *p) {}becomesstatic int foo(MyStruct *p);which is unlikely workable, as tag space differs from identifiers space in C
Expected behavior:
- The declaration of
staticfunctions shall/should always be directed to the same file the functions are in - The
structtype specifier shall always be retained in C, as it directs identifiers in the tag namespace
Configuration and Logs
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x86",
"configurationProvider": "ms-vscode.makefile-tools",
}
],
"version": 4
}
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
Reproduce the issue with a static function and a struct parameter in main.c, then invoke the “C/C++: Create Declaration/Definition” command and inspect the generated main.h. Trace the command’s declaration-generation entry point and add coverage for keeping static declarations in main.c and preserving the struct specifier; done means both generated declarations remain valid C.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100