https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85110

--- Comment #9 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Author: dmalcolm
Date: Thu Dec  6 15:25:12 2018
New Revision: 266856

URL: https://gcc.gnu.org/viewcvs?rev=266856&root=gcc&view=rev
Log:
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.


Added:
    trunk/gcc/testsuite/g++.dg/diagnostic/missing-default-args.C
    trunk/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch-3.C
    trunk/gcc/testsuite/g++.dg/warn/Wconversion-null-4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C

Reply via email to