diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5211,7 +5211,8 @@ // trivial in almost all cases, except if a union member has an in-class // initializer: // union { int n = 0; }; - ActOnUninitializedDecl(Anon); + if (!Invalid) + ActOnUninitializedDecl(Anon); } Anon->setImplicit(); diff --git a/clang/test/SemaCXX/PR49534.cpp b/clang/test/SemaCXX/PR49534.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/PR49534.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify + +static union { // expected-warning {{declaration does not declare anything}} + virtual int a(); // expected-error {{unions cannot have virtual functions}} \ + // expected-error {{functions cannot be declared in an anonymous union}} +};