@@ -1127,6 +1127,17 @@ sort_mem_initializers (tree t, tree mem_
return sorted_inits;
}
+/* Callback for cp_walk_tree to mark all PARM_DECLs in a tree as read. */
+
+static tree
+mark_exp_read_r (tree *tp, int *, void *)
+{
+ tree t = *tp;
+ if (TREE_CODE (t) == PARM_DECL)
+ mark_exp_read (t);
+ return NULL_TREE;
+}
+
/* Initialize all bases and members of CURRENT_CLASS_TYPE. MEM_INITS
is a TREE_LIST giving the explicit mem-initializer-list for the
constructor. The TREE_PURPOSE of each entry is a subobject (a
@@ -1217,12 +1228,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
+ else if (arguments != void_type_node)
/* 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));
+ cp_walk_tree (&TREE_VALUE (arg), mark_exp_read_r, NULL, NULL);
if (inherited_base)
pop_deferring_access_checks ();
@@ -0,0 +1,12 @@
+// PR c++/79782
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-but-set-parameter -Wunused-parameter" }
+
+struct E { virtual E *foo () const = 0; };
+struct F : virtual public E { };
+struct G : public virtual F { G (int x) : F () { } }; // { dg-warning "unused parameter" }
+struct H : virtual public E { H (int x, int y); };
+struct I : public virtual H { I (int x, int y) : H (x, y) { } }; // { dg-bogus "set but not used" }
+struct J : public virtual H { J (int x, int y) : H { x, y } { } }; // { dg-bogus "set but not used" }
+struct K : public virtual H { K (int x, int y) : H (x * 0, y + 1) { } }; // { dg-bogus "set but not used" }
+struct L : public virtual H { L (int x, int y) : H { x & 0, y | 1 } { } }; // { dg-bogus "set but not used" }