vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

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

Open ktbarrett opened this issue 3 years ago • 3 comments

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

ktbarrett avatar Apr 03 '22 14:04 ktbarrett

Thanks for reporting this. One potential workaround is to add "-fms-extensions" to compilerArgs, although it seems possible that using that could cause other unexpected errors to occur. I've filed bug 1514310 in our shared VS parser database.

sean-mcmanus avatar Apr 04 '22 19:04 sean-mcmanus

Where can I track status on that bug report?

ktbarrett avatar Jul 15 '22 14:07 ktbarrett

Via this GitHub issue. If there's any state change we'll update this issue. So far there hasn't been any change.

sean-mcmanus avatar Jul 15 '22 19:07 sean-mcmanus