Introduce a stack of instantiation scopes that are used to store the mapping from variable declarations that occur within templates to their instantiated counterparts

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71799 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 89d88ff..d7b0854 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -85,6 +85,15 @@
                                                  *Arg.getAsIntegral(),
                                                  T, 
                                        E->getSourceRange().getBegin()));
+  } else if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
+    ParmVarDecl *ParmInst 
+      = SemaRef.CurrentInstantiationScope->getInstantiationOf(Parm);
+    QualType T = ParmInst->getType();
+    return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(ParmInst,
+                                                      T.getNonReferenceType(),
+                                                           E->getLocation(),
+                                                        T->isDependentType(),
+                                                        T->isDependentType()));
   } else
     assert(false && "Can't handle arbitrary declaration references");