Skip to content

Anonymous union members initialized with designated initializers does not compile inside template #65143

@liss-h

Description

@liss-h

The following code fails to compile on at least clang-14,15,16:

struct Inner {
};

struct Outer {
    union {
        Inner inner;
    };
};

template<typename>
void f() {
    Outer x{.inner = {}};
}
        
int main() {
    f<int>();
}

With the following message:

error: field designator (null) does not refer to any field in type 'Outer'
<source>:16:5: note: in instantiation of function template specialization 'f<int>' requested here
    f<int>();
    ^

Removing the template on f resolves the error.

Godbolt: https://godbolt.org/z/Tod1oa1Gd

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions