Hi!

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?

2017-02-28  Jakub Jelinek  <ja...@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

Reply via email to