]> granicus.if.org Git - clang/commitdiff
Improve the diagnostic for bad conversions in overload resolution to talk
authorJohn McCall <rjmccall@apple.com>
Thu, 14 Jan 2010 00:56:20 +0000 (00:56 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 14 Jan 2010 00:56:20 +0000 (00:56 +0000)
about 'object argument' vs. 'nth argument'.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOverload.cpp
test/SemaCXX/overload-call.cpp
test/SemaCXX/overload-member-call.cpp

index 1173863b910d76e4475b1410a174d48af03320ed..d3b27c08e9ab87ff6112de2d45197eaf7625c639 100644 (file)
@@ -923,7 +923,8 @@ def note_ovl_candidate_bad_conv : Note<"candidate "
     "constructor (the implicit default constructor)|"
     "constructor (the implicit copy constructor)|"
     "function (the implicit copy assignment operator)}0%1"
-    " not viable: no known conversion from %2 to %3 for argument %4">;
+    " not viable: no known conversion from %2 to %3 for "
+    "%select{%ordinal5 argument|object argument}4">;
 def note_ambiguous_type_conversion: Note<
     "because of ambiguity in conversion of %0 to %1">;
 def note_ovl_builtin_binary_candidate : Note<
index 5abca9989681541c81e628b7452e7f9ae155ac7e..9111cf46b50d5a47c4f8812e1c6c2e8751c3a85a 100644 (file)
@@ -4388,7 +4388,7 @@ void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, unsigned I) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_conv)
     << (unsigned) FnKind << FnDesc
     << (FromExpr ? FromExpr->getSourceRange() : SourceRange())
-    << FromTy << ToTy << I+1;
+    << FromTy << ToTy << (unsigned) isObjectArgument << I+1;
 }
 
 void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
index acd1e50afe44e6e56220ff51216bffe505d5a60b..d20bf23b8fd95a61f6a99f74c1bd3e4361c56451 100644 (file)
@@ -304,8 +304,8 @@ namespace PR5756 {
 
 // Tests the exact text used to note the candidates
 namespace test1 {
-  template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for argument 2}}
-  void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for argument 2}} 
+  template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for 2nd argument}}
+  void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for 2nd argument}} 
   void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}}
   void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}}
   void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
index 8eb189850b66e98b9966db226084a3d8aac5f54c..700e6d8bc6b9e7ca439c1abaa92a7af2294b0046 100644 (file)
@@ -70,18 +70,24 @@ void test_X2(X2 *x2p, const X2 *cx2p) {
 // Tests the exact text used to note the candidates
 namespace test1 {
   class A {
-    template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for argument 2}}
-    void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for argument 2}} 
+    template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for 2nd argument}}
+    void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for 2nd argument}} 
     void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}}
     void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}}
     void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
     void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
     void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
+
+    void bar(double d); //expected-note {{candidate function not viable: no known conversion from 'class test1::A const' to 'class test1::A' for object argument}}
+    void bar(int i); //expected-note {{candidate function not viable: no known conversion from 'class test1::A const' to 'class test1::A' for object argument}}
   };
 
   void test() {
     A a;
     a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}}
+
+    const A b;
+    b.bar(0); //expected-error {{no matching member function for call to 'bar'}}
   }
 }