From ee686729283500c330b8b920f4f8e4dcc566adde Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 20 Nov 2019 09:33:56 +0100 Subject: [PATCH] re PR c++/90767 (jumbled error message with this and const) 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 | 7 +++++++ gcc/cp/call.c | 5 ++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/diagnostic/pr90767-1.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/diagnostic/pr90767-2.C | 15 +++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr90767-1.C create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr90767-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 34af32c9f19..6031acf3609 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-11-20 Jakub Jelinek + + 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 * cvt.c (ocp_convert): Use additional warning sentinel. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f4dfa7b3f56..cccb90f4f99 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7de7a43dc41..a6086a4807c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2019-11-20 Jakub Jelinek + 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 index 00000000000..7d1cd3db398 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/pr90767-1.C @@ -0,0 +1,15 @@ +// PR c++/90767 +// { dg-do compile } + +struct X { + int n; + void foo (); // { dg-message "initializing argument 'this'" } + + template + 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 index 00000000000..550762b2db9 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/pr90767-2.C @@ -0,0 +1,15 @@ +// PR c++/90767 +// { dg-do compile } + +struct A { + struct B { B (int) {} }; + + template + void foo () + { + int x = 0; + bar (x); // { dg-error "cannot convert 'int' to 'A::B&'" } + } + + void bar (B &arg) {} // { dg-message "initializing argument 1" } +}; -- 2.30.2