r188334 - Don't produce duplicate notes if we have deduction failure notes when resolving

Richard Smith richard-llvm at metafoo.co.uk
Tue Aug 13 17:00:45 PDT 2013


Author: rsmith
Date: Tue Aug 13 19:00:44 2013
New Revision: 188334

URL: http://llvm.org/viewvc/llvm-project?rev=188334&view=rev
Log:
Don't produce duplicate notes if we have deduction failure notes when resolving
the address of an overloaded function template.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CXX/over/over.over/p2.cpp
    cfe/trunk/test/SemaCXX/addr-of-overloaded-function-casting.cpp
    cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
    cfe/trunk/test/SemaObjCXX/arc-nsconsumed-errors.mm

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=188334&r1=188333&r2=188334&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Aug 13 19:00:44 2013
@@ -9390,7 +9390,6 @@ private:
       FailedCandidates.addCandidate()
           .set(FunctionTemplate->getTemplatedDecl(),
                MakeDeductionFailureInfo(Context, Result, Info));
-      (void)Result;
       return false;
     } 
     
@@ -9531,10 +9530,22 @@ public:
     S.Diag(OvlExpr->getLocStart(), diag::err_addr_ovl_no_viable)
         << OvlExpr->getName() << TargetFunctionType
         << OvlExpr->getSourceRange();
-    FailedCandidates.NoteCandidates(S, OvlExpr->getLocStart());
-    S.NoteAllOverloadCandidates(OvlExpr, TargetFunctionType);
-  } 
-  
+    if (FailedCandidates.empty())
+      S.NoteAllOverloadCandidates(OvlExpr, TargetFunctionType);
+    else {
+      // We have some deduction failure messages. Use them to diagnose
+      // the function templates, and diagnose the non-template candidates
+      // normally.
+      for (UnresolvedSetIterator I = OvlExpr->decls_begin(),
+                                 IEnd = OvlExpr->decls_end();
+           I != IEnd; ++I)
+        if (FunctionDecl *Fun =
+                dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl()))
+          S.NoteOverloadCandidate(Fun, TargetFunctionType);
+      FailedCandidates.NoteCandidates(S, OvlExpr->getLocStart());
+    }
+  }
+
   bool IsInvalidFormOfPointerToMemberFunction() const {
     return TargetTypeIsNonStaticMemberFunction &&
       !OvlExprInfo.HasFormOfMemberPointer;
@@ -9695,7 +9706,6 @@ Sema::ResolveSingleFunctionTemplateSpeci
       FailedCandidates.addCandidate()
           .set(FunctionTemplate->getTemplatedDecl(),
                MakeDeductionFailureInfo(Context, Result, Info));
-      (void)Result;
       continue;
     }
 

Modified: cfe/trunk/test/CXX/over/over.over/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.over/p2.cpp?rev=188334&r1=188333&r2=188334&view=diff
==============================================================================
--- cfe/trunk/test/CXX/over/over.over/p2.cpp (original)
+++ cfe/trunk/test/CXX/over/over.over/p2.cpp Tue Aug 13 19:00:44 2013
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 template <typename T>
-T f0(T, T); // expected-note{{candidate}} expected-note{{candidate function}}
+T f0(T, T); // expected-note{{deduced conflicting types for parameter 'T' ('int' vs. 'float')}}
 
 void test_f0() {
   int (*f0a)(int, int) = f0;

Modified: cfe/trunk/test/SemaCXX/addr-of-overloaded-function-casting.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/addr-of-overloaded-function-casting.cpp?rev=188334&r1=188333&r2=188334&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/addr-of-overloaded-function-casting.cpp (original)
+++ cfe/trunk/test/SemaCXX/addr-of-overloaded-function-casting.cpp Tue Aug 13 19:00:44 2013
@@ -5,10 +5,10 @@ void f(); // expected-note 9{{candidate
 void f(int); // expected-note 9{{candidate function}}
 
 template <class T>
-void t(T); // expected-note 6{{candidate function}} \
+void t(T); // expected-note 3{{candidate function}} \
            // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}}
 template <class T>
-void t(T *); // expected-note 6{{candidate function}} \
+void t(T *); // expected-note 3{{candidate function}} \
              // expected-note 3{{candidate template ignored: could not match 'void' against 'int'}}
 
 template<class T> void u(T);

Modified: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp?rev=188334&r1=188333&r2=188334&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Tue Aug 13 19:00:44 2013
@@ -159,8 +159,7 @@ namespace Templates {
   double &mem_check4 = take_fn<double>(Outer<double>::arg_multi);
 
   namespace Deduce1 {
-  template <typename T> auto f() { return 0; } // expected-note {{candidate}} \
-                                               // expected-note {{candidate function has different return type ('int' expected but has 'auto')}}
+  template <typename T> auto f() { return 0; } // expected-note {{couldn't infer template argument 'T'}}
     template<typename T> void g(T(*)()); // expected-note 2{{candidate}}
     void h() {
       auto p = f<int>;
@@ -173,8 +172,7 @@ namespace Templates {
   }
 
   namespace Deduce2 {
-  template <typename T> auto f(int) { return 0; } // expected-note {{candidate}} \
-    // expected-note {{candidate function has different return type ('int' expected but has 'auto')}}
+  template <typename T> auto f(int) { return 0; } // expected-note {{couldn't infer template argument 'T'}}
     template<typename T> void g(T(*)(int)); // expected-note 2{{candidate}}
     void h() {
       auto p = f<int>;

Modified: cfe/trunk/test/SemaObjCXX/arc-nsconsumed-errors.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-nsconsumed-errors.mm?rev=188334&r1=188333&r2=188334&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-nsconsumed-errors.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-nsconsumed-errors.mm Tue Aug 13 19:00:44 2013
@@ -29,8 +29,7 @@ void releaser(__attribute__((ns_consumed
 releaser_t r2 = releaser; // no-warning
 
 template <typename T>
-void templateFunction(T) { } // expected-note {{candidate function}} \
-                             // expected-note {{candidate template ignored: could not match 'void (__strong id)' against 'void (id)'}} \
+void templateFunction(T) { } // expected-note {{candidate template ignored: could not match 'void (__strong id)' against 'void (id)'}} \
                              // expected-note {{candidate template ignored: failed template argument deduction}}
 releaser_t r3 = templateFunction<id>; // expected-error {{address of overloaded function 'templateFunction' does not match required type 'void (id)'}}
 





More information about the cfe-commits mailing list