From: Richard Smith Date: Wed, 20 Jun 2018 23:36:55 +0000 (+0000) Subject: When a dependent alignas is applied to a non-dependent typedef, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc8d6b0b1110ed2dfdf4c9196500306f84db6b3f;p=clang When a dependent alignas is applied to a non-dependent typedef, prioritize the error for the bad subject over the error for the dependent / non-dependent mismatch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 779192b865..614432b0e2 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -3440,16 +3440,6 @@ static void handleAlignedAttr(Sema &S, Decl *D, const AttributeList &AL) { if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E)) return; - if (E->isValueDependent()) { - if (const auto *TND = dyn_cast(D)) { - if (!TND->getUnderlyingType()->isDependentType()) { - S.Diag(AL.getLoc(), diag::err_alignment_dependent_typedef_name) - << E->getSourceRange(); - return; - } - } - } - S.AddAlignedAttr(AL.getRange(), D, E, AL.getAttributeSpellingListIndex(), AL.isPackExpansion()); } @@ -3496,7 +3486,18 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, } } - if (E->isTypeDependent() || E->isValueDependent()) { + if (E->isValueDependent()) { + // We can't support a dependent alignment on a non-dependent type, + // because we have no way to model that a type is "alignment-dependent" + // but not dependent in any other way. + if (const auto *TND = dyn_cast(D)) { + if (!TND->getUnderlyingType()->isDependentType()) { + Diag(AttrLoc, diag::err_alignment_dependent_typedef_name) + << E->getSourceRange(); + return; + } + } + // Save dependent expressions in the AST to be instantiated. AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr); AA->setPackExpansion(IsPackExpansion); diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp new file mode 100644 index 0000000000..ec7b22f753 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +typedef int A alignas(4); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} +template void f() { + typedef int B alignas(N); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} +}