Skip to content

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

@felix642

Description

@felix642

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions