<div dir="ltr">ping.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 29, 2015 at 7:13 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rsmith,<br>
<br>
A dependent alignment attribute (like __attribute__((aligned(...))) or<br>
__declspec(align(...))) on a non-dependent typedef or using declaration<br>
poses a considerable challenge: the type is _not_ dependent, the size<br>
_may_ be dependent if the type is used as an array type, the alignment<br>
_is_ dependent.<br>
<br>
It is reasonable for a compiler to be able to query the size and<br>
alignment of a complete type.  Let's help that become an invariant.<br>
<br>
This fixes PR22042.<br>
<br>
<a href="http://reviews.llvm.org/D8693" target="_blank">http://reviews.llvm.org/D8693</a><br>
<br>
Files:<br>
  include/clang/Basic/DiagnosticSemaKinds.td<br>
  lib/Sema/SemaDeclAttr.cpp<br>
  test/SemaCXX/alignof.cpp<br>
<br>
Index: include/clang/Basic/DiagnosticSemaKinds.td<br>
===================================================================<br>
--- include/clang/Basic/DiagnosticSemaKinds.td<br>
+++ include/clang/Basic/DiagnosticSemaKinds.td<br>
@@ -2134,6 +2134,8 @@<br>
<br>
 def err_alignment_not_power_of_two : Error<<br>
   "requested alignment is not a power of 2">;<br>
+def err_alignment_dependent_typedef_name : Error<<br>
+  "requested alignment is dependent but declaration is not dependent">;<br>
<br>
 def err_attribute_aligned_too_great : Error<<br>
   "requested alignment must be %0 bytes or smaller">;<br>
Index: lib/Sema/SemaDeclAttr.cpp<br>
===================================================================<br>
--- lib/Sema/SemaDeclAttr.cpp<br>
+++ lib/Sema/SemaDeclAttr.cpp<br>
@@ -2863,6 +2863,17 @@<br>
   if (!Attr.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))<br>
     return;<br>
<br>
+  if (E->isTypeDependent() || E->isValueDependent()) {<br>
+    if (const auto *TND = dyn_cast<TypedefNameDecl>(D)) {<br>
+      QualType T = TND->getUnderlyingType();<br>
+      if (!T->isDependentType() && !T->isInstantiationDependentType()) {<br>
+        S.Diag(Attr.getLoc(), diag::err_alignment_dependent_typedef_name)<br>
+            << E->getSourceRange();<br>
+        return;<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
   S.AddAlignedAttr(Attr.getRange(), D, E, Attr.getAttributeSpellingListIndex(),<br>
                    Attr.isPackExpansion());<br>
 }<br>
Index: test/SemaCXX/alignof.cpp<br>
===================================================================<br>
--- test/SemaCXX/alignof.cpp<br>
+++ test/SemaCXX/alignof.cpp<br>
@@ -84,3 +84,11 @@<br>
   static_assert(sizeof(k) == alignof(long long), "");<br>
 }<br>
 template void n(long long);<br>
+<br>
+namespace PR22042 {<br>
+template <typename T><br>
+void Fun(T A) {<br>
+  typedef int __attribute__((__aligned__(A))) T1; // expected-error {{requested alignment is dependent but declaration is not dependent}}<br>
+  int k1[__alignof__(T1)];<br>
+}<br>
+}<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</blockquote></div><br></div>