diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 52669132be889..117449f4e2fad 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -528,6 +528,9 @@ Bug Fixes in This Version statement expression that appears outside of a function block scope. The assertion was benign outside of asserts builds and would only fire in C. (`#48579 _`). +- Fixed a failing assertion when applying an attribute to an anonymous union. + The assertion was benign outside of asserts builds and would only fire in C++. + (`#48512 _`). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9fe1cb20a76f6..f33542e05b983 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5716,10 +5716,10 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, SC = SC_None; } - assert(DS.getAttributes().empty() && "No attribute expected"); Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(), Record->getLocation(), /*IdentifierInfo=*/nullptr, Context.getTypeDeclType(Record), TInfo, SC); + ProcessDeclAttributes(S, Anon, Dc); // Default-initialize the implicit variable. This initialization will be // trivial in almost all cases, except if a union member has an in-class diff --git a/clang/test/SemaCXX/anonymous-union.cpp b/clang/test/SemaCXX/anonymous-union.cpp index 27dd2f0083b8a..0f1a972d0aa05 100644 --- a/clang/test/SemaCXX/anonymous-union.cpp +++ b/clang/test/SemaCXX/anonymous-union.cpp @@ -215,3 +215,8 @@ namespace PR16630 { b.y = 0; // expected-error {{'y' is a private member of 'PR16630::A'}} } } + +namespace GH48512 { + // This would previously cause an assertion in C++ mode. + static __attribute__((a)) union { int a; }; // expected-warning {{unknown attribute 'a' ignored}} +}