]> granicus.if.org Git - clang/commitdiff
When performing template argument deduction of a function template
authorDouglas Gregor <dgregor@apple.com>
Wed, 29 Sep 2010 21:14:36 +0000 (21:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 29 Sep 2010 21:14:36 +0000 (21:14 +0000)
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

lib/Sema/SemaOverload.cpp
lib/Sema/SemaTemplateDeduction.cpp
test/SemaCXX/addr-of-overloaded-function.cpp

index 919aea8d024abab2b88822d30c3ef2ae1641ed25..92d68bba66e7ebb380aa77427578588cf5b3f734 100644 (file)
@@ -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(),
index 5c77ed61060bdbc7854f76b77062162d22a4783a..f3ffa716f1b90c33a00439e5772f4534fc81384d 100644 (file)
@@ -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
index 46bdf8e6b65acea93665b96c976ea4477a284251..ab80d8f14165c6e43fa212aa15f3e1c00e3d251c 100644 (file)
@@ -104,3 +104,15 @@ namespace PR8033 {
   // 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'}}
+  }
+}