On Wed, Mar 28, 2018 at 4:44 PM, David Malcolm <dmalc...@redhat.com> wrote:
> This followup patch updates the specific error-handling path
> to add a note showing the pertinent parameter decl, taking
> the output from:
>
> 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);
>               ^~~
>
> to:
>
> 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);
>               ^~~
> test.cc:1:36: note:   initializing argument 2 of 'void callee(int, const 
> char**, int)'
>  void callee (int one, const char **two, int three);
>                        ~~~~~~~~~~~~~^~~
>
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; adds
> a further 18 PASS results to g++.sum.
>
> Again, not a regression as such, but I've been calling out the underlined
> arguments as a feature of gcc 8, so would be good to fix.
>
> OK for trunk?
>
> gcc/cp/ChangeLog:
>         PR c++/85110
>         * call.c (get_fndecl_argument_location): Make non-static.
>         * cp-tree.h (get_fndecl_argument_location): New decl.
>         * typeck.c (convert_for_assignment): When complaining due to
>         conversions for an argument, show the location of the parameter
>         within the decl.
>
> gcc/testsuite/ChangeLog:
>         PR c++/85110
>         * g++.dg/diagnostic/param-type-mismatch-2.C: Update for the cases
>         where we now show the pertinent parameter.
> ---
>  gcc/cp/call.c                                       |  2 +-
>  gcc/cp/cp-tree.h                                    |  2 ++
>  gcc/cp/typeck.c                                     | 10 +++++++---
>  .../g++.dg/diagnostic/param-type-mismatch-2.C       | 21 
> ++++++++++++++++++---
>  4 files changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/cp/call.c b/gcc/cp/call.c
> index 1a87f99..e1a0639 100644
> --- a/gcc/cp/call.c
> +++ b/gcc/cp/call.c
> @@ -6598,7 +6598,7 @@ maybe_print_user_conv_context (conversion *convs)
>     ARGNUM is zero based, -1 indicates the `this' argument of a method.
>     Return the location of the FNDECL itself if there are problems.  */
>
> -static location_t
> +location_t
>  get_fndecl_argument_location (tree fndecl, int argnum)
>  {
>    int i;
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index d5382c2..b45880d 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -5965,6 +5965,8 @@ extern bool can_convert_arg                       
> (tree, tree, tree, int,
>                                                  tsubst_flags_t);
>  extern bool can_convert_arg_bad                        (tree, tree, tree, 
> int,
>                                                  tsubst_flags_t);
> +extern location_t get_fndecl_argument_location  (tree, int);
> +
>
>  /* A class for recording information about access failures (e.g. private
>     fields), so that we can potentially supply a fix-it hint about
> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
> index e733c79..742b2e9 100644
> --- a/gcc/cp/typeck.c
> +++ b/gcc/cp/typeck.c
> @@ -8781,9 +8781,13 @@ convert_for_assignment (tree type, tree rhs,
>                                                    parmnum, complain, flags);
>                 }
>               else if (fndecl)
> -               error_at (EXPR_LOC_OR_LOC (rhs, input_location),
> -                         "cannot convert %qH to %qI for argument %qP to %qD",
> -                         rhstype, type, parmnum, fndecl);
> +               {
> +                 error_at (EXPR_LOC_OR_LOC (rhs, input_location),
> +                           "cannot convert %qH to %qI for argument %qP to 
> %qD",
> +                           rhstype, type, parmnum, fndecl);
> +                 inform (get_fndecl_argument_location (fndecl, parmnum),
> +                         "  initializing argument %P of %qD", parmnum, 
> fndecl);

If you're adding the inform, you don't need the %P of %D in the initial error.

Jason

Reply via email to