aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-09-29 21:14:36 +0000
committerDouglas Gregor <dgregor@apple.com>2010-09-29 21:14:36 +0000
commitfbb6fad63acac2bef36cfa13e0706fa3e2a1ed7d (patch)
tree8ac8312e4c7b6fea13887092cce0413127a0e326 /lib
parente24724893a2f9cb1d660b2e1d5b7b8b899aedb3d (diff)
When performing template argument deduction of a function template
against a function type, be sure to check the type of the resulting function template specialization against the desired function type after substituting the deduced/defaulted template arguments. Fixes PR8196. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaOverload.cpp4
-rw-r--r--lib/Sema/SemaTemplateDeduction.cpp18
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 919aea8d02..92d68bba66 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -6348,8 +6348,8 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
// FIXME: make a note of the failed deduction for diagnostics.
(void)Result;
} else {
- // FIXME: If the match isn't exact, shouldn't we just drop this as
- // a candidate? Find a testcase before changing the code.
+ // Template argument deduction ensures that we have an exact match.
+ // This function template specicalization works.
assert(FunctionType
== Context.getCanonicalType(Specialization->getType()));
Matches.push_back(std::make_pair(I.getPair(),
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 5c77ed6106..f3ffa716f1 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -1865,10 +1865,20 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
Deduced, 0))
return Result;
}
-
- return FinishTemplateArgumentDeduction(FunctionTemplate, Deduced,
- NumExplicitlySpecified,
- Specialization, Info);
+
+ if (TemplateDeductionResult Result
+ = FinishTemplateArgumentDeduction(FunctionTemplate, Deduced,
+ NumExplicitlySpecified,
+ Specialization, Info))
+ return Result;
+
+ // If the requested function type does not match the actual type of the
+ // specialization, template argument deduction fails.
+ if (!ArgFunctionType.isNull() &&
+ !Context.hasSameType(ArgFunctionType, Specialization->getType()))
+ return TDK_NonDeducedMismatch;
+
+ return TDK_Success;
}
/// \brief Deduce template arguments for a templated conversion