C++: improvements to diagnostics using %P (more PR c++/85110)
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 6 Dec 2018 15:25:12 +0000 (15:25 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 6 Dec 2018 15:25:12 +0000 (15:25 +0000)
commitf11854d42ab072a260ab9ee019a527acf03c5107
treec2bcf15443a85c921a7d1c8a6cbc1477771dfcde
parent51948daf1ceb71db9d5682df42c6da079acaf3d7
C++: improvements to diagnostics using %P (more PR c++/85110)

This patch is based on grepping the C++ frontend for %P
i.e. diagnostics that refer to a parameter number.  It fixes up
these diagnostics to highlight the pertinent param where appropriate
(and possible), along with various other tweaks, as described in the
ChangeLog.

gcc/cp/ChangeLog:
PR c++/85110
* call.c (conversion_null_warnings): Try to use the location of
the expression for the warnings.  Add notes showing the parameter
of the function decl, where available.
(get_fndecl_argument_location): For implicitly-declared functions,
use the fndecl location rather than that of the param.
(maybe_inform_about_fndecl_for_bogus_argument_init): New function.
(convert_like_real): Use it in various places to avoid repetition.
(complain_about_bad_argument): Likewise.
* cp-tree.h (maybe_inform_about_fndecl_for_bogus_argument_init):
New declaration.
* decl2.c (check_default_args): Put all diagnostics for the fndecl
into a diagnostic group.  Use the location of the parameter when
complaining about parameters with missing default arguments in
preference to that of the fndecl.  Attempt to record the location
of the first parameter with a default argument and emit a note
for the first parameter that's missing one.
* typeck.c (convert_arguments): When complaining about parameters
with incomplete types, attempt to use the location of the
argument.  Where available, add a note showing the pertinent
parameter in the fndecl.
(convert_for_assignment): When complaining about bad conversions
at function calls, use the location of the unstripped argument.
(convert_for_initialization): When checking for bogus references,
add an auto_diagnostic_group, and update the note to use the
location of the pertinent parameter, rather than just the callee.

gcc/testsuite/ChangeLog:
PR c++/85110
* g++.dg/diagnostic/missing-default-args.C: New test.
* g++.dg/diagnostic/param-type-mismatch-3.C: New test.
* g++.dg/diagnostic/param-type-mismatch.C: Add tests for invalid
references and incomplete types.
* g++.dg/warn/Wconversion-null-4.C: New test.

From-SVN: r266856
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/missing-default-args.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/param-type-mismatch-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C
gcc/testsuite/g++.dg/warn/Wconversion-null-4.C [new file with mode: 0644]