r335191 - When a dependent alignas is applied to a non-dependent typedef,

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 20 16:36:55 PDT 2018


Author: rsmith
Date: Wed Jun 20 16:36:55 2018
New Revision: 335191

URL: http://llvm.org/viewvc/llvm-project?rev=335191&view=rev
Log:
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.

Added:
    cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=335191&r1=335190&r2=335191&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jun 20 16:36:55 2018
@@ -3440,16 +3440,6 @@ static void handleAlignedAttr(Sema &S, D
   if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))
     return;
 
-  if (E->isValueDependent()) {
-    if (const auto *TND = dyn_cast<TypedefNameDecl>(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 At
     }
   }
 
-  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<TypedefNameDecl>(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);

Added: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp?rev=335191&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.align/p1.cpp Wed Jun 20 16:36:55 2018
@@ -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<int N> void f() {
+  typedef int B alignas(N); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}}
+}




More information about the cfe-commits mailing list