[cfe-commits] r116332 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/deduction.cpp

John McCall rjmccall at apple.com
Tue Oct 12 12:40:14 PDT 2010


Author: rjmccall
Date: Tue Oct 12 14:40:14 2010
New Revision: 116332

URL: http://llvm.org/viewvc/llvm-project?rev=116332&view=rev
Log:
Enter the context of the declared function template when performing
deduction and the final substitution, but not while substituting the
explicit template arguments.  Fixes rdar://problem/8537391


Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=116332&r1=116331&r2=116332&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Oct 12 14:40:14 2010
@@ -1218,8 +1218,6 @@
   if (Inst)
     return TDK_InstantiationDepth;
 
-  ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl());
-
   if (CheckTemplateArgumentList(FunctionTemplate,
                                 SourceLocation(),
                                 ExplicitTemplateArgs,
@@ -1238,6 +1236,12 @@
     = new (Context) TemplateArgumentList(Context, Builder, /*TakeArgs=*/true);
   Info.reset(ExplicitArgumentList);
 
+  // Template argument deduction and the final substitution should be
+  // done in the context of the templated declaration.  Explicit
+  // argument substitution, on the other hand, needs to happen in the
+  // calling context.
+  ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl());
+
   // Instantiate the types of each of the function parameters given the
   // explicitly-specified template arguments.
   for (FunctionDecl::param_iterator P = Function->param_begin(),

Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=116332&r1=116331&r2=116332&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Tue Oct 12 14:40:14 2010
@@ -134,3 +134,19 @@
     f(0, p);
   }
 }
+
+// rdar://problem/8537391
+namespace test3 {
+  struct Foo {
+    template <void F(char)> static inline void foo();
+  };
+
+  class Bar {
+    template<typename T> static inline void wobble(T ch);
+
+  public:
+    static void madness() {
+      Foo::foo<wobble<char> >();
+    }
+  };
+}





More information about the cfe-commits mailing list