From e3e9e8ca83de62be68d8b589e9ddf9638f0e8366 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 1 Mar 2017 09:35:55 +0100 Subject: [PATCH] re PR c++/79746 (Confusing -Wunused-but-set-parameter warning with virtual inheritance) 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. From-SVN: r245802 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/init.c | 6 ++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/warn/Wunused-parm-9.C | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b0e589c..1c3f1e8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2017-03-01 Jakub Jelinek + + PR c++/79746 + * init.c (emit_mem_initializers): When not constructing vbases of + abstract classes, mark arguments as read for + -Wunused-but-set-parameter. + 2017-02-28 Jason Merrill Class template argument deduction refinements diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 5520963..7ded37e 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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 (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3692337..4cce675 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-03-01 Jakub Jelinek + PR c++/79746 + * g++.dg/warn/Wunused-parm-9.C: New test. + PR tree-optimization/79734 * g++.dg/opt/pr79734.C: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-9.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-9.C new file mode 100644 index 0000000..0dcc229 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-9.C @@ -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" } +}; -- 2.7.4