Implement dependent alignment attribute support. This is a bit gross given the
current attribute system, but it is enough to handle class templates which
specify parts of their alignment in terms of their template parameters.

This also replaces the attributes test in SemaTemplate with one that actually
tests working attributes instead of broken ones. I plan to add more tests here
for non-dependent attributes in a subsequent patch.

Thanks to John for walking me through some of this. =D


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106818 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 1b28579..06f38e8 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -143,14 +143,29 @@
   return false;
 }
 
-// FIXME: Is this too simple?
+// FIXME: Is this still too simple?
 void TemplateDeclInstantiator::InstantiateAttrs(Decl *Tmpl, Decl *New) {
-  for (const Attr *TmplAttr = Tmpl->getAttrs(); TmplAttr; 
+  for (const Attr *TmplAttr = Tmpl->getAttrs(); TmplAttr;
        TmplAttr = TmplAttr->getNext()) {
-    
+    // FIXME: This should be generalized to more than just the AlignedAttr.
+    if (const AlignedAttr *Aligned = dyn_cast<AlignedAttr>(TmplAttr)) {
+      if (Aligned->isDependent()) {
+        // The alignment expression is not potentially evaluated.
+        EnterExpressionEvaluationContext Unevaluated(SemaRef,
+                                                     Action::Unevaluated);
+
+        OwningExprResult Result = SemaRef.SubstExpr(Aligned->getAlignmentExpr(),
+                                                    TemplateArgs);
+        if (!Result.isInvalid())
+          // FIXME: Is this the correct source location?
+          SemaRef.AddAlignedAttr(Aligned->getAlignmentExpr()->getExprLoc(),
+                                 New, Result.takeAs<Expr>());
+        continue;
+      }
+    }
+
     // FIXME: Is cloning correct for all attributes?
     Attr *NewAttr = TmplAttr->clone(SemaRef.Context);
-    
     New->addAttr(NewAttr);
   }
 }