summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-10-12 19:40:14 +0000
committerJohn McCall <rjmccall@apple.com>2010-10-12 19:40:14 +0000
commit036855a0ed4d88eea36a064e51c3e2b20f8d1496 (patch)
treea1e3ba3f75681b882be2a23e62bf86be379e6e51
parentf062c2fb5940065fd14aca8045e7432c87216933 (diff)
downloadbcm5719-llvm-036855a0ed4d88eea36a064e51c3e2b20f8d1496.tar.gz
bcm5719-llvm-036855a0ed4d88eea36a064e51c3e2b20f8d1496.zip
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 llvm-svn: 116332
-rw-r--r--clang/lib/Sema/SemaTemplateDeduction.cpp8
-rw-r--r--clang/test/SemaTemplate/deduction.cpp16
2 files changed, 22 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6237610c098..ce3748b901a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1218,8 +1218,6 @@ Sema::SubstituteExplicitTemplateArguments(
if (Inst)
return TDK_InstantiationDepth;
- ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl());
-
if (CheckTemplateArgumentList(FunctionTemplate,
SourceLocation(),
ExplicitTemplateArgs,
@@ -1238,6 +1236,12 @@ Sema::SubstituteExplicitTemplateArguments(
= 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(),
diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp
index 9400a0aba96..cf98d6e0ac4 100644
--- a/clang/test/SemaTemplate/deduction.cpp
+++ b/clang/test/SemaTemplate/deduction.cpp
@@ -134,3 +134,19 @@ namespace test2 {
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> >();
+ }
+ };
+}
OpenPOWER on IntegriCloud