diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -396,8 +396,10 @@ const AttrVec &V = getAttrs(); ASTContext &Ctx = getASTContext(); specific_attr_iterator I(V.begin()), E(V.end()); - for (; I != E; ++I) - Align = std::max(Align, I->getAlignment(Ctx)); + for (; I != E; ++I) { + if (!I->isAlignmentDependent()) + Align = std::max(Align, I->getAlignment(Ctx)); + } return Align; } diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp --- a/clang/test/AST/ast-dump-recovery.cpp +++ b/clang/test/AST/ast-dump-recovery.cpp @@ -97,4 +97,9 @@ void test(int x) { foo.abc; foo->func(x); -} \ No newline at end of file +} + +// CHECK: |-AlignedAttr {{.*}} alignas +// CHECK-NEXT:| `-RecoveryExpr {{.*}} contains-errors +// CHECK-NEXT:| `-UnresolvedLookupExpr {{.*}} 'invalid' +struct alignas(invalid()) Aligned {}; diff --git a/clang/test/SemaCXX/invalid-aligned-attr.cpp b/clang/test/SemaCXX/invalid-aligned-attr.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/invalid-aligned-attr.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -frecovery-ast -verify %s +// RUN: %clang_cc1 -verify %s + +struct alignas(invalid()) Foo {}; // expected-error {{use of undeclared identifier}} + +constexpr int k = alignof(Foo);