[cfe-commits] r80394 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-member-template.cpp

Douglas Gregor dgregor at apple.com
Fri Aug 28 14:09:48 PDT 2009


Author: dgregor
Date: Fri Aug 28 16:09:48 2009
New Revision: 80394

URL: http://llvm.org/viewvc/llvm-project?rev=80394&view=rev
Log:
Fix and test template instantiation for nested member templates.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-member-template.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=80394&r1=80393&r2=80394&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Aug 28 16:09:48 2009
@@ -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)

Modified: cfe/trunk/test/SemaTemplate/instantiate-member-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-member-template.cpp?rev=80394&r1=80393&r2=80394&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-member-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-member-template.cpp Fri Aug 28 16:09:48 2009
@@ -41,9 +41,22 @@
       U z; // expected-error{{void}}
     };
   };
+  
+  template<typename U>
+  struct Inner3 {
+    void f0(T t, U u) {
+      (void)(t + u); // expected-error{{invalid operands}}
+    }
+    
+    template<typename V>
+    V f1(T t, U u, V) {
+      return t + u; // expected-error{{incompatible type}}
+    }
+  };
+  
 };
 
-void test_X1() {
+void test_X1(int *ip, int i, double *dp) {
   X1<void>::Inner0<int> *xvip; // okay
   X1<void>::Inner0<int> xvi; // expected-note{{instantiation}}
   
@@ -52,4 +65,13 @@
   
   X1<int>::Inner2<void>::SuperInner *xisivp; // okay
   X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}}
+  
+  X1<int*>::Inner3<int> id3;
+  id3.f0(ip, i);
+  id3.f0(dp, i); // expected-error{{incompatible type}}
+  id3.f1(ip, i, ip);
+  id3.f1(ip, i, dp); // expected-note{{instantiation}}
+  
+  X1<int*>::Inner3<double*> id3b;
+  id3b.f0(ip, dp); // expected-note{{instantiation}}
 }





More information about the cfe-commits mailing list