Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] Fix-it for modernize-use-designated-initializers does not correctly handle nested structs #110600

Open
felix642 opened this issue Sep 30, 2024 · 0 comments

Comments

@felix642
Copy link
Contributor

Let's assume the following code :

struct A
{
    struct B
    {
        int c;
    } b;
    int a;
};

void foo()
{
    A a{0, 1};
}

The Fix-it for modernize-use-designated-initializers will generate the following code :

struct A
{
    struct B
    {
        int c;
    } b;
    int a;
};

void foo()
{
    A a{.b.c=0, .a=1};
}

For which the compiler will emit this warning: warning nested designators are a C99 extension [-Wc99-designator]

The correct fix would be : A a{.b={.c=0}, .a=1};

godbolt: https://godbolt.org/z/Tjjrjz4e3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant