[cfe-commits] r115086 - in /cfe/trunk: lib/Sema/SemaOverload.cpp lib/Sema/SemaTemplateDeduction.cpp test/SemaCXX/addr-of-overloaded-function.cpp
Douglas Gregor
dgregor at apple.com
Wed Sep 29 14:14:37 PDT 2010
Author: dgregor
Date: Wed Sep 29 16:14:36 2010
New Revision: 115086
URL: http://llvm.org/viewvc/llvm-project?rev=115086&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=115086&r1=115085&r2=115086&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Sep 29 16:14:36 2010
@@ -6348,8 +6348,8 @@
// 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(),
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=115086&r1=115085&r2=115086&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Sep 29 16:14:36 2010
@@ -1865,10 +1865,20 @@
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
Modified: cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp?rev=115086&r1=115085&r2=115086&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp Wed Sep 29 16:14:36 2010
@@ -104,3 +104,15 @@
// expected-error{{cannot initialize a variable of type}}
}
+
+namespace PR8196 {
+ template <typename T> struct mcdata {
+ typedef int result_type;
+ };
+ template <class T>
+ typename mcdata<T>::result_type wrap_mean(mcdata<T> const&);
+ void add_property(double(*)(mcdata<double> const &)); // expected-note{{candidate function not viable: no overload of 'wrap_mean' matching}}
+ void f() {
+ add_property(&wrap_mean); // expected-error{{no matching function for call to 'add_property'}}
+ }
+}
More information about the cfe-commits
mailing list