Skip to content

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

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

Closed
liss-h opened this issue Aug 31, 2023 · 2 comments · Fixed by #69712
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@liss-h
Copy link

liss-h commented Aug 31, 2023

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

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Aug 31, 2023
@llvmbot
Copy link
Member

llvmbot commented Aug 31, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Aug 31, 2023

Confirmed.

@shafik shafik added the confirmed Verified by a second party label Aug 31, 2023
Fznamznon added a commit to Fznamznon/llvm-project that referenced this issue Oct 20, 2023
Skip anonymous members when rebuilding DesignatedInitExpr since designated
inits for them are meant to be created during
`InitListChecker::CheckDesignatedInitializer` routine.

Fixes llvm#65143
Fznamznon added a commit that referenced this issue Oct 23, 2023
Skip anonymous members when rebuilding `DesignatedInitExpr` since
designated inits for them are meant to be created during
`InitListChecker::CheckDesignatedInitializer` routine.

Fixes #65143
ahatanaka pushed a commit to swiftlang/llvm-project that referenced this issue Nov 3, 2023
Skip anonymous members when rebuilding `DesignatedInitExpr` since
designated inits for them are meant to be created during
`InitListChecker::CheckDesignatedInitializer` routine.

Fixes llvm#65143
ahatanaka pushed a commit to swiftlang/llvm-project that referenced this issue Nov 7, 2023
Skip anonymous members when rebuilding `DesignatedInitExpr` since
designated inits for them are meant to be created during
`InitListChecker::CheckDesignatedInitializer` routine.

Fixes llvm#65143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants