diff options
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 16 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/instantiate-attr.cpp | 7 | 
2 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 7288ae29a0e..5ae7289ea56 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -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/clang/test/SemaTemplate/instantiate-attr.cpp b/clang/test/SemaTemplate/instantiate-attr.cpp new file mode 100644 index 00000000000..08ba9c3a0cd --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-attr.cpp @@ -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]; +  | 

