]> granicus.if.org Git - clang/commitdiff
Don't assert when attempting to take the address of an overloaded
authorDouglas Gregor <dgregor@apple.com>
Sun, 12 Sep 2010 08:16:09 +0000 (08:16 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 12 Sep 2010 08:16:09 +0000 (08:16 +0000)
function fails due to ambiguities in partial ordering of function
templates. Fixes PR8033.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113725 91177308-0d34-0410-b5e6-96231b3b80d8

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

index cf67f0bdd00fb665e2da7c950ad53e6d27773b42..bd971b793aefec0f6b706bd4d37e1ff89fdef6af 100644 (file)
@@ -6430,7 +6430,9 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
                                << Matches[0].second->getDeclName(),
                            PDiag(diag::note_ovl_candidate)
                                << (unsigned) oc_function_template);
-    assert(Result != MatchesCopy.end() && "no most-specialized template");
+    if (Result == MatchesCopy.end())
+      return 0;
+    
     MarkDeclarationReferenced(From->getLocStart(), *Result);
     FoundResult = Matches[Result - MatchesCopy.begin()].first;
     if (Complain) {
index b581b8a3f64908f117891bb910bbfe61c169cc41..46bdf8e6b65acea93665b96c976ea4477a284251 100644 (file)
@@ -96,3 +96,11 @@ namespace PR7971 {
     static bool g(int, char);
   };
 }
+
+namespace PR8033 {
+  template <typename T1, typename T2> int f(T1 *, const T2 *); // expected-note{{candidate function [with T1 = const int, T2 = int]}}
+  template <typename T1, typename T2> int f(const T1 *, T2 *); // expected-note{{candidate function [with T1 = int, T2 = const int]}}
+  int (*p)(const int *, const int *) = f; // expected-error{{address of overloaded function 'f' is ambiguous}} \
+  // expected-error{{cannot initialize a variable of type}}
+
+}