]> granicus.if.org Git - clang/commitdiff
When instantiating a field decl, make sure to clone its attributes. With this change...
authorAnders Carlsson <andersca@mac.com>
Sat, 7 Nov 2009 06:07:58 +0000 (06:07 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 7 Nov 2009 06:07:58 +0000 (06:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86344 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-attr.cpp [new file with mode: 0644]

index 7288ae29a0e368297eec173e839a2096b7b79646..5ae7289ea56202f61028fd3a20b4c28e973af908 100644 (file)
@@ -28,6 +28,8 @@ namespace {
     DeclContext *Owner;
     const MultiLevelTemplateArgumentList &TemplateArgs;
 
+    void InstantiateAttrs(Decl *Tmpl, Decl *New);
+      
   public:
     typedef Sema::OwningExprResult OwningExprResult;
 
@@ -89,6 +91,18 @@ namespace {
   };
 }
 
+// FIXME: Is this too simple?
+void TemplateDeclInstantiator::InstantiateAttrs(Decl *Tmpl, Decl *New) {
+  for (const Attr *TmplAttr = Tmpl->getAttrs(); TmplAttr; 
+       TmplAttr = TmplAttr->getNext()) {
+    
+    // FIXME: Is cloning correct for all attributes?
+    Attr *NewAttr = TmplAttr->clone(SemaRef.Context);
+    
+    New->addAttr(NewAttr);
+  }
+}
+
 Decl *
 TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
   assert(false && "Translation units cannot be instantiated");
@@ -258,6 +272,8 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
     return 0;
   }
 
+  InstantiateAttrs(D, Field);
+  
   if (Invalid)
     Field->setInvalidDecl();
 
diff --git a/test/SemaTemplate/instantiate-attr.cpp b/test/SemaTemplate/instantiate-attr.cpp
new file mode 100644 (file)
index 0000000..08ba9c3
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template <typename T>
+struct A {
+  char a __attribute__((aligned(16)));
+};
+int a[sizeof(A<int>) == 16 ? 1 : -1];
+