microsoft / vscode-cpptools

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

Designated initializers squiggles #12239

Open grishalipenko opened 4 months ago

grishalipenko commented 4 months ago

Environment

Bug Summary and Steps to Reproduce

Unexpected errors with code using designated initializer https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers:

struct A
{
    explicit A() = default;
};

struct B
{
    A a;
    std::string str;
};

void foo()
{
    std::string_view other;
    [[maybe_unused]] B b{.a{}, .str{other}};
}

Designated1 Designated2

Configuration and Logs

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "path/to/my/compile_commands.json"
        }
    ],
    "version": 4
}

Other Extensions

No response

Additional context

No response

sean-mcmanus commented 4 months ago

@grishalipenko I've reported VS bugs https://developercommunity.visualstudio.com/t/C-IntelliSense-incorrectly-reports-E0/10643601 and https://developercommunity.visualstudio.com/t/C-IntelliSense-incorrectly-reports-err/10643609 to track these issues (for our shared IntelliSense code). FYI, the string code doesn't compile with gcc, but it does with clang and cl.exe so the IntelliSense errors are incorrect still, although I'm not sure which compilers are behaving correctly, i.e. it could be a gcc bug too.