]> granicus.if.org Git - clang/commitdiff
When instantiating a typedef of an anonymous tag type, note in the tag
authorDouglas Gregor <dgregor@apple.com>
Fri, 23 Apr 2010 16:25:07 +0000 (16:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 23 Apr 2010 16:25:07 +0000 (16:25 +0000)
declaration that this typedef gives the tag a name. Fixes a problem
uncovered by Boost.GIL (Generic Image Library).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102180 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/temp_arg_type.cpp

index 10fe176148f0aeb44ee7718702d5c4f4cb43beeb..fe60be062c12096842fe6998b99b3fcc7acfd29c 100644 (file)
@@ -200,12 +200,22 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
   if (Invalid)
     Typedef->setInvalidDecl();
 
+  if (const TagType *TT = DI->getType()->getAs<TagType>()) {
+    TagDecl *TD = TT->getDecl();
+    
+    // If the TagDecl that the TypedefDecl points to is an anonymous decl
+    // keep track of the TypedefDecl.
+    if (!TD->getIdentifier() && !TD->getTypedefForAnonDecl())
+      TD->setTypedefForAnonDecl(Typedef);
+  }
+  
   if (TypedefDecl *Prev = D->getPreviousDeclaration()) {
     NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev,
                                                        TemplateArgs);
     Typedef->setPreviousDeclaration(cast<TypedefDecl>(InstPrev));
   }
 
+
   Typedef->setAccess(D->getAccess());
   Owner->addDecl(Typedef);
 
index eea7297b533f0c250fcab0034aa4142aad5f74de..3876c256455de84ab23015b47e1bfd5cfd434820 100644 (file)
@@ -30,5 +30,13 @@ void f() {
 struct { int x; } Unnamed; // expected-note{{unnamed type used in template argument was declared here}}
 A<__typeof__(Unnamed)> *a9; // expected-error{{template argument uses unnamed type}}
 
+template<typename T, unsigned N>
+struct Array {
+  typedef struct { T x[N]; } type;
+};
+
+template<typename T> struct A1 { };
+A1<Array<int, 17>::type> ax;
+
 // FIXME: [temp.arg.type]p3. The check doesn't really belong here (it
 // belongs somewhere in the template instantiation section).