microsoft / microsoft/vscode-cpptools

Errors calling functions with enum type parameters that are defined in structs

Open
#9,131 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Language Service verified Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Bug type: Language Service

Describe the bug

  • OS and Version: Ubuntu 2021.10
  • VS Code Version: 1.65.2
  • C/C++ Extension Version: v1.9.2
  • Other extensions you installed (and if the issue persists after disabling them): None
  • If using SSH remote, specify OS of remote machine: N/A

If an enum type is defined in a struct and that enum type is used as the type of a function parameter all attempts to pass a value on that parameter will cause an error.

Steps to reproduce
Copy-paste the below code.

Expected behavior
This should not error. Neither gcc nor clang consider this an error or even a warning (with -Weverything).

Code sample and logs

struct Foo {
    enum FooType {
        A, B, C
    } type;
};

void use_FooType(enum FooType type) { (void)type; }

void call_with_enum(void)
{
    enum FooType type = A;
    use_FooType(type);  // argument of type "enum FooType" is incompatible with parameter of type "enum FooType"
}

void call_with_int(void)
{
    use_FooType(A);  // argument of type "int" is incompatible with parameter of type "enum FooType"
}
Configurations in `c_cpp_properties.json`
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/include"
            ],
            "defines": [],
            "compilerPath": "/usr/lib/ccache/clang",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}
Logs from running `C/C++: Log Diagnostics` from the VS Code command palette
-------- Diagnostics - 4/3/2022, 9:50:00 AM
Version: 1.9.7
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/include"
    ],
    "defines": [],
    "compilerPath": "/usr/lib/ccache/clang",
    "cStandard": "c17",
    "cppStandard": "c++20",
    "intelliSenseMode": "linux-clang-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerArgs": [],
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/include",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/kaleb/dev/scratch/foo.c ]:
    /home/kaleb/dev/scratch/foo.c
Translation Unit Configurations:
[ /home/kaleb/dev/scratch/foo.c ]:
    Process ID: 4394
    Memory Usage: 17 MB
    Compiler Path: /usr/lib/ccache/clang
    Includes:
        /home/kaleb/dev/scratch/include
        /usr/lib/llvm-13/lib/clang/13.0.0/include
        /home/kaleb/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-clang-x64
    Other Flags:
        --clang
        --clang_version=130000
Total Memory Usage: 17 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4941

Logs from the language server logging

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced foo.c code sample and the linked language-server logs, then trace how the language service resolves enum types declared inside structs and diagnoses function arguments. Done means the sample produces no false errors for either enum variables or the enumerator A, while gcc and clang behavior remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, typescript
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.