OK.

On Thu, Mar 8, 2018 at 12:53 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> On Thu, Mar 08, 2018 at 10:08:20AM -0500, Jason Merrill wrote:
>> On Wed, Mar 7, 2018 at 5:19 PM, Jakub Jelinek <ja...@redhat.com> wrote:
>> > This testcase regressed when the mark_used call in finish_id_expression
>> > has been guarded with if (done).  Wonder if we can't just mark it TREE_USED
>> > otherwise for the benefit of -Wunused-function and leave it
>> > non-DECL_ODR_USED as it should.  Or do we want to mark it TREE_USED
>> > elsewhere?
>>
>> Probably in the processing_template_decl block near the top of 
>> build_over_call.
>
> This works too.  Ok for trunk then (passed bootstrap/regtest on x86_64-linux
> and i686-linux)?
>
> 2018-03-08  Jason Merrill  <ja...@redhat.com>
>             Jakub Jelinek  <ja...@redhat.com>
>
>         PR c++/80598
>         * call.c (build_over_call): In templates set TREE_USED (first_fn) when
>         not calling mark_used for the benefit of -Wunused-function warning.
>
>         * g++.dg/warn/Wunused-function4.C: New test.
>
> --- gcc/cp/call.c.jj    2018-03-08 10:58:58.157373982 +0100
> +++ gcc/cp/call.c       2018-03-08 16:18:19.897340581 +0100
> @@ -7634,6 +7634,10 @@ build_over_call (struct z_candidate *can
>
>        if (undeduced_auto_decl (fn))
>         mark_used (fn, complain);
> +      else
> +       /* Otherwise set TREE_USED for the benefit of -Wunused-function.
> +          See PR80598.  */
> +       TREE_USED (fn) = 1;
>
>        return_type = TREE_TYPE (TREE_TYPE (fn));
>        nargs = vec_safe_length (args);
> --- gcc/testsuite/g++.dg/warn/Wunused-function4.C.jj    2018-03-08 
> 16:16:23.756274559 +0100
> +++ gcc/testsuite/g++.dg/warn/Wunused-function4.C       2018-03-08 
> 16:16:23.756274559 +0100
> @@ -0,0 +1,21 @@
> +// PR c++/80598
> +// { dg-do compile }
> +// { dg-options "-Wunused-function" }
> +
> +static void
> +foo ()         // { dg-bogus "defined but not used" }
> +{
> +}
> +
> +static void
> +bar ()         // { dg-warning "defined but not used" }
> +{
> +}
> +
> +template <class T>
> +int
> +baz (T x)
> +{
> +  foo ();
> +  return 0;
> +}
>
>
>         Jakub

Reply via email to