diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2827,6 +2827,8 @@ /// [C++0x] assignment-expression ...[opt] ExprResult Parser::ParseAlignArgument(SourceLocation Start, SourceLocation &EllipsisLoc) { + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult ER; if (isTypeIdInParens()) { SourceLocation TypeLoc = Tok.getLocation(); @@ -2834,8 +2836,9 @@ SourceRange TypeRange(Start, Tok.getLocation()); ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, Ty.getAsOpaquePtr(), TypeRange); - } else - ER = ParseConstantExpression(); + } else { + ER = ParseConstantExpressionInExprEvalContext(); + } if (getLangOpts().CPlusPlus11) TryConsumeToken(tok::ellipsis, EllipsisLoc); diff --git a/clang/test/AST/alignas_maybe_odr_cleanup.cpp b/clang/test/AST/alignas_maybe_odr_cleanup.cpp new file mode 100644 --- /dev/null +++ b/clang/test/AST/alignas_maybe_odr_cleanup.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s + +struct FOO { + static const int vec_align_bytes = 32; + void foo() { + double a alignas(vec_align_bytes); + ; + } +}; + +// CHECK: AlignedAttr {{.*}} alignas +// CHECK: ConstantExpr {{.+}} 'int' Int: 32 +// CHECK: ImplicitCastExpr {{.*}} 'int' +// CHECK: DeclRefExpr {{.*}} 'const int' lvalue Var {{.*}} 'vec_align_bytes' 'const int' non_odr_use_constant +// CHECK: NullStmt