Add basic, hackish support for instantiation of typedefs in a class
template. More importantly, start to sort out the issues regarding
complete types and nested-name-specifiers, especially the question of:
when do we instantiate a class template specialization that occurs to
the left of a '::' in a nested-name-specifier?




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66662 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 21694b2..d630e80 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -655,13 +655,44 @@
   // Start the definition of this instantiation.
   ClassTemplateSpec->startDefinition();
 
-  // FIXME: Create the injected-class-name for the
-  // instantiation. Should this be a typedef or something like it?
 
   // Instantiate the base class specifiers.
   if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template))
     Invalid = true;
 
+  // FIXME: Create the injected-class-name for the
+  // instantiation. Should this be a typedef or something like it?
+
+  RecordDecl *Pattern = Template->getTemplatedDecl();
+
+  for (RecordDecl::decl_iterator Member = Pattern->decls_begin(),
+                              MemberEnd = Pattern->decls_end();
+       Member != MemberEnd; ++Member) {
+    if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(*Member)) {
+      // FIXME: Simplified instantiation of typedefs needs to be made
+      // "real".
+      QualType T = Typedef->getUnderlyingType();
+      if (T->isDependentType()) {
+        T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(),
+                            ClassTemplateSpec->getNumTemplateArgs(),
+                            Typedef->getLocation(),
+                            Typedef->getDeclName());
+        if (T.isNull()) {
+          Invalid = true;
+          T = Context.IntTy;
+        }
+      }
+       
+      // Create the new typedef
+      TypedefDecl *New 
+        = TypedefDecl::Create(Context, ClassTemplateSpec,
+                              Typedef->getLocation(),
+                              Typedef->getIdentifier(),
+                              T);
+      ClassTemplateSpec->addDecl(New);
+    }
+  }
+
   // FIXME: Instantiate all of the members.
   
   // Add any implicitly-declared members that we might need.