This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix -Wunused-but-set-parameter in ctors of some abstract classes (PR c++/79746)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>
- Date: Tue, 28 Feb 2017 14:41:22 -1000
- Subject: Re: [C++ PATCH] Fix -Wunused-but-set-parameter in ctors of some abstract classes (PR c++/79746)
- Authentication-results: sourceware.org; auth=none
- References: <20170228224834.GU1849@tucnak>
On Tue, Feb 28, 2017 at 12:48 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> The DR1659/DR1611 changes result in construct_virtual_base not being called,
> but unfortunately the call generated in there was the spot that caused
> mark_exp_read on the arguments passed to the vbase construction (TREE_USED
> is set on these earlier already during parsing them). That results
> in false positive -Wunused-but-set-parameter warnings.
>
> The following patch tries to avoid the warning in that case by marking
> the arguments as read (essentially pretending they were read in the omitted
> call). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
I believe there's some question still about whether the DR1659/11
changes are what we want; I'll defer to Nathan on this patch.
Jason
> 2017-02-28 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/79746
> * init.c (emit_mem_initializers): When not constructing vbases of
> abstract classes, mark arguments as read for
> -Wunused-but-set-parameter.
>
> * g++.dg/warn/Wunused-parm-9.C: New test.
>
> --- gcc/cp/init.c.jj 2017-02-28 16:24:05.000000000 +0100
> +++ gcc/cp/init.c 2017-02-28 21:08:29.158380881 +0100
> @@ -1217,6 +1217,12 @@ emit_mem_initializers (tree mem_inits)
> /* C++14 DR1658 Means we do not have to construct vbases of
> abstract classes. */
> construct_virtual_base (subobject, arguments);
> + else
> + /* When not constructing vbases of abstract classes, at least mark
> + the arguments expressions as read to avoid
> + -Wunused-but-set-parameter false positives. */
> + for (tree arg = arguments; arg; arg = TREE_CHAIN (arg))
> + mark_exp_read (TREE_VALUE (arg));
>
> if (inherited_base)
> pop_deferring_access_checks ();
> --- gcc/testsuite/g++.dg/warn/Wunused-parm-9.C.jj 2017-02-28 21:11:44.989820368 +0100
> +++ gcc/testsuite/g++.dg/warn/Wunused-parm-9.C 2017-02-28 21:10:43.000000000 +0100
> @@ -0,0 +1,12 @@
> +// PR c++/79746
> +// { dg-do compile }
> +// { dg-options "-Wunused-but-set-parameter" }
> +
> +struct A {
> + A (const char *x) : a(x) {} // { dg-bogus "set but not used" }
> + virtual int foo () = 0;
> + const char *a;
> +};
> +struct B : public virtual A {
> + B (const char *x) : A(x) {} // { dg-bogus "set but not used" }
> +};
>
> Jakub