]> granicus.if.org Git - clang/commitdiff
Fix two issues with the substitution of template template parameters
authorDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 19:54:12 +0000 (19:54 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 5 Feb 2010 19:54:12 +0000 (19:54 +0000)
when instantiating the declaration of a member template:
  - Only check if the have a template template argument at a specific position
  when we already know that we have template arguments at that level;
  otherwise, we're substituting for a level-reduced template template
  parameter.
  - When trying to find an instantiated declaration for a template
  template parameter, look into the instantiated scope. This was a
  typo, where we had two checks for TemplateTypeParmDecl, one of
  which should have been a TemplateTemplateParmDecl.

With these changes, tramp3d-v4 passes -fsyntax-only.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95421 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/member-function-template.cpp

index 5c5701ac792dc0001eda79321b71ec79d9c64d57..ab66ef3dfdfaacaf5ee406b6220132ed4a2a1b08 100644 (file)
@@ -578,6 +578,14 @@ Decl *TemplateInstantiator::TransformDecl(Decl *D) {
 
   if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
     if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
+      // If the corresponding template argument is NULL or non-existent, it's
+      // because we are performing instantiation from explicitly-specified
+      // template arguments in a function template, but there were some
+      // arguments left unspecified.
+      if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
+                                            TTP->getPosition()))
+        return D;
+
       TemplateName Template
         = TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsTemplate();
       assert(!Template.isNull() && Template.getAsTemplateDecl() &&
@@ -585,14 +593,6 @@ Decl *TemplateInstantiator::TransformDecl(Decl *D) {
       return Template.getAsTemplateDecl();
     }
 
-    // If the corresponding template argument is NULL or non-existent, it's
-    // because we are performing instantiation from explicitly-specified
-    // template arguments in a function template, but there were some
-    // arguments left unspecified.
-    if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
-                                          TTP->getPosition()))
-      return D;
-
     // Fall through to find the instantiated declaration for this template
     // template parameter.
   }
index 6597a853a80801d5fed919821e5d585100302a02..e4017c5630bf3f19a40162cde2e2dc70ef194732 100644 (file)
@@ -2159,7 +2159,7 @@ NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D,
                           const MultiLevelTemplateArgumentList &TemplateArgs) {
   DeclContext *ParentDC = D->getDeclContext();
   if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) ||
-      isa<TemplateTypeParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
+      isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D) ||
       ParentDC->isFunctionOrMethod()) {
     // D is a local of some kind. Look into the map of local
     // declarations to their instantiations.
index 5ea8c1010e5c60bd52ef3c38e82a7c181250c790..aea62855c2255fd756020e1e8b6d478bdc8c7af8 100644 (file)
@@ -73,3 +73,15 @@ void test_incomplete_access(X1<int> *x1, X2<int> *x2) {
   float &fr = x1->get<float>();
   (void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}}
 }
+
+// Instantiation of template template parameters in a member function
+// template.
+namespace TTP {
+  template<int Dim> struct X {
+    template<template<class> class M, class T> void f(const M<T>&);
+  };
+
+  template<typename T> struct Y { };
+
+  void test_f(X<3> x, Y<int> y) { x.f(y); }
+}