Fix and test template instantiation for nested member templates.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80394 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2138557..732394d 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -947,9 +947,12 @@
   
   // Find the function body that we'll be substituting.
   const FunctionDecl *PatternDecl = 0;
-  if (FunctionTemplateDecl *Primary = Function->getPrimaryTemplate())
+  if (FunctionTemplateDecl *Primary = Function->getPrimaryTemplate()) {
+    while (Primary->getInstantiatedFromMemberTemplate())
+      Primary = Primary->getInstantiatedFromMemberTemplate();
+    
     PatternDecl = Primary->getTemplatedDecl();
-  else 
+  } else 
     PatternDecl = Function->getInstantiatedFromMemberFunction();
   Stmt *Pattern = 0;
   if (PatternDecl)