microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.46k stars 1.53k forks source link

'const __auto_type' gives mystery 'must be a placeholder for the complete type' error #6054

Open yseymour opened 4 years ago

yseymour commented 4 years ago

Type: LanguageService

Describe the bug

Steps to reproduce

test.c

typedef union { int foo; } foo;
int main() {
    const __auto_type f = (foo){ 1234 };
}

Gives the error: '__auto_type' must be a placeholder for the complete type of the variable (not for a component of that type). Removing const resolves the error.

gcc and clang both compile the code without error.

I had difficulty working out whether this error is being produced by the extension, or some other tool. Googling the message did not uncover anything. Hopefully someone can work it out.

My c_cpp_properties.json looks like:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}",
                <snip>
            ],
            "defines": [
                <snip>
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
sean-mcmanus commented 4 years ago

I've reported a bug against our parser shared with VS at https://developercommunity.visualstudio.com/content/problem/1168897/incorrect-c-intellisense-error-in-gcc-mode-auto-ty.html .

A potential workaround is to add these lines somewhere in the TU:

#ifdef __INTELLISENSE__
    #pragma diag_suppress 2717
    #pragma diag_suppress 144
#endif