C++: improvements to diagnostics using %P (more PR c++/85110)
commit9683081b9feb71947ec93ba7fdeb72f0d515db53
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 6 Dec 2018 15:25:12 +0000 (6 15:25 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 6 Dec 2018 15:25:12 +0000 (6 15:25 +0000)
treec2bcf15443a85c921a7d1c8a6cbc1477771dfcde
parent23eb46c4a575d361f3a7db2f9d378e9f86a95d93
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@266856 138bc75d-0d04-0410-961f-82ee72b054a4
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]