Instantiate unresolved using declarations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80366 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 4874c92..5d1c059 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2160,8 +2160,9 @@
         << NNS << RD->getDeclName();
       return 0;
     }
-    
-    LookupContext = cast<RecordType>(Ty)->getDecl();
+
+    QualType BaseTy = Context.getCanonicalType(QualType(Ty, 0));
+    LookupContext = BaseTy->getAs<RecordType>()->getDecl();
   } else {
     // C++0x N2914 [namespace.udecl]p8:
     // A using-declaration for a class member shall be a member-declaration.
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0bf832f..4f9fcc3 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -58,7 +58,8 @@
     Decl *VisitClassTemplateDecl(ClassTemplateDecl *D);
     Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
     Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
-
+    Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D);
+      
     // Base case. FIXME: Remove once we can instantiate everything.
     Decl *VisitDecl(Decl *) { 
       assert(false && "Template instantiation of unknown declaration kind!");
@@ -740,6 +741,24 @@
   return Inst;
 }
 
+Decl *
+TemplateDeclInstantiator::VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D) {
+  NestedNameSpecifier *NNS = 
+    SemaRef.SubstNestedNameSpecifier(D->getTargetNestedNameSpecifier(), 
+                                     D->getTargetNestedNameRange(), 
+                                     TemplateArgs);
+  if (!NNS)
+    return 0;
+  
+  CXXScopeSpec SS;
+  SS.setRange(D->getTargetNestedNameRange());
+  SS.setScopeRep(NNS);
+  
+  return SemaRef.BuildUsingDeclaration(D->getLocation(), SS, 
+                                       D->getTargetNameLocation(), 
+                                       D->getTargetName(), 0, D->isTypeName());
+}
+
 Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner,
                       const TemplateArgumentList &TemplateArgs) {
   TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);