diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 715e8757d43f64..8f68be716bd37a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5025,6 +5025,8 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, /*BitWidth=*/nullptr, /*Mutable=*/false, /*InitStyle=*/ICIS_NoInit); Anon->setAccess(AS); + ProcessDeclAttributes(S, Anon, Dc); + if (getLangOpts().CPlusPlus) FieldCollector->Add(cast(Anon)); } else { @@ -5038,6 +5040,7 @@ 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); diff --git a/clang/test/AST/pr43983.cpp b/clang/test/AST/pr43983.cpp new file mode 100644 index 00000000000000..0f4f596361aa11 --- /dev/null +++ b/clang/test/AST/pr43983.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s + +struct B { _Alignas(64) struct { int b; }; }; + +// CHECK: AlignedAttr {{.*}} _Alignas +// CHECK: ConstantExpr {{.*}} 64 +// CHECK: IntegerLiteral {{.*}} 64