More underlining of bad arguments (PR c++/85110)
commit128fe6cd7d5aa6c3c724b8179bd7e4f0e8d9c97b
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Mar 2018 14:43:01 +0000 (29 14:43 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Mar 2018 14:43:01 +0000 (29 14:43 +0000)
tree6c668bbd9b0202aef0d490ddb3cf228f557bb0dd
parent0251a2a79bbb7a3ed87b884b7636b0852772b7dd
More underlining of bad arguments (PR c++/85110)

As of r256448, the C++ frontend underlines many bad arguments in its
diagnostics; those where perform_overload_resolution returns a
non-NULL candidate, but there's a failure in convert_like_real.

However, for the case where perform_overload_resolution fails, but
there's a single non-viable candidate, the error is diagnosed by
cp_build_function_call_vec, and that currently doesn't underline
the bad argument:

$ cat test.cc
void callee (int one, const char **two, int three);

void
caller (const char *fmt)
{
  callee (1, fmt, 3);
}

We emit:

$ g++ test.cc
test.cc: In function 'void caller(const char*)':
test.cc:6:20: error: cannot convert 'const char*' to 'const char**' for argument '2' to 'void callee(int, const char**, int)'
   callee (1, fmt, 3);
                    ^

It's going through convert_for_assignment, and
implicitly using input_location.

This patch updates convert_for_assignment for this case, using
an EXPR_LOCATION if there is one, or falling back to input_location
otherwise, underlining the argument in question:

test.cc: In function 'void caller(const char*)':
test.cc:6:14: error: cannot convert 'const char*' to 'const char**' for argument '2' to 'void callee(int, const char**, int)'
   callee (1, fmt, 3);
              ^~~

gcc/cp/ChangeLog:
PR c++/85110
* typeck.c (convert_for_assignment): When complaining due to
conversions for an argument, attempt to use the location of the
argument.

gcc/testsuite/ChangeLog:
PR c++/85110
* g++.dg/diagnostic/param-type-mismatch-2.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258957 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/param-type-mismatch-2.C [new file with mode: 0644]