re PR c++/90767 (jumbled error message with this and const)
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Nov 2019 08:33:56 +0000 (09:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 20 Nov 2019 08:33:56 +0000 (09:33 +0100)
PR c++/90767
* call.c (complain_about_no_candidates_for_method_call): If
conv->from is not a type, pass to complain_about_bad_argument
lvalue_type of conv->from.

* g++.dg/diagnostic/pr90767-1.C: New test.
* g++.dg/diagnostic/pr90767-2.C: New test.

From-SVN: r278484

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/pr90767-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/pr90767-2.C [new file with mode: 0644]

index 34af32c9f194e42dab616c889aee6e01682dcfd8..6031acf360918e19ef982c142e5854ef79c400f1 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/90767
+       * call.c (complain_about_no_candidates_for_method_call): If
+       conv->from is not a type, pass to complain_about_bad_argument
+       lvalue_type of conv->from.
+
 2019-11-20  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * cvt.c (ocp_convert): Use additional warning sentinel.
index f4dfa7b3f56bcb2a62a76df28f1e30f0d5414ce2..cccb90f4f99e62ce85a580d285243c93b0f8df0b 100644 (file)
@@ -9871,8 +9871,11 @@ complain_about_no_candidates_for_method_call (tree instance,
          if (const conversion_info *conv
                = maybe_get_bad_conversion_for_unmatched_call (candidate))
            {
+             tree from_type = conv->from;
+             if (!TYPE_P (conv->from))
+               from_type = lvalue_type (conv->from);
              complain_about_bad_argument (conv->loc,
-                                          conv->from, conv->to_type,
+                                          from_type, conv->to_type,
                                           candidate->fn, conv->n_arg);
              return;
            }
index 7de7a43dc41b4018de226ab5c54ee38a6468817a..a6086a4807cad5aca9254e73dfe98c26e6b73ef8 100644 (file)
@@ -1,5 +1,9 @@
 2019-11-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/90767
+       * g++.dg/diagnostic/pr90767-1.C: New test.
+       * g++.dg/diagnostic/pr90767-2.C: New test.
+
        PR middle-end/90840
        * gcc.c-torture/compile/pr90840.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr90767-1.C b/gcc/testsuite/g++.dg/diagnostic/pr90767-1.C
new file mode 100644 (file)
index 0000000..7d1cd3d
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/90767
+// { dg-do compile }
+
+struct X {
+  int n;
+  void foo (); // { dg-message "initializing argument 'this'" }
+
+  template<typename T>
+  operator T () const
+    {
+      if (n == 0)
+       foo (); // { dg-error "cannot convert 'const X\\*' to 'X\\*'" }
+      return n;
+    }
+};
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr90767-2.C b/gcc/testsuite/g++.dg/diagnostic/pr90767-2.C
new file mode 100644 (file)
index 0000000..550762b
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/90767
+// { dg-do compile }
+
+struct A {
+  struct B { B (int) {} };
+
+  template <typename T>
+  void foo ()
+  {
+    int x = 0;
+    bar (x);   // { dg-error "cannot convert 'int' to 'A::B&'" }
+  }
+
+  void bar (B &arg) {} // { dg-message "initializing argument 1" }
+};