Hi! Jason's recent change removed a mark_rvalue_use call from constant_value_1, which unfortunately regressed quite a few cases where -Wunused-but-set-variable now has false positives.
The easiest fix seems to be just deal with the -Wunused-but-set-variable issue at that point. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-05 Jakub Jelinek <ja...@redhat.com> PR c++/82728 PR c++/82799 PR c++/83690 * init.c (constant_value_1): Call mark_exp_read on decl. * g++.dg/warn/Wunused-var-27.C: New test. * g++.dg/warn/Wunused-var-28.C: New test. * g++.dg/warn/Wunused-var-29.C: New test. --- gcc/cp/init.c.jj 2018-01-03 10:20:17.296537499 +0100 +++ gcc/cp/init.c 2018-01-05 16:48:27.914911810 +0100 @@ -2211,6 +2211,7 @@ constant_value_1 (tree decl, bool strict initializer for the static data member is not processed until needed; we need it now. */ mark_used (decl, tf_none); + mark_exp_read (decl); init = DECL_INITIAL (decl); if (init == error_mark_node) { --- gcc/testsuite/g++.dg/warn/Wunused-var-27.C.jj 2018-01-05 16:44:15.647814313 +0100 +++ gcc/testsuite/g++.dg/warn/Wunused-var-27.C 2018-01-05 16:44:05.774810218 +0100 @@ -0,0 +1,14 @@ +// PR c++/82728 +// { dg-do compile } +// { dg-options "-Wunused-but-set-variable" } + +void +foo () +{ + const int i = 1; // { dg-bogus "set but not used" } + switch (0) + { + case i: + break; + } +} --- gcc/testsuite/g++.dg/warn/Wunused-var-28.C.jj 2018-01-05 16:44:27.158819090 +0100 +++ gcc/testsuite/g++.dg/warn/Wunused-var-28.C 2018-01-05 16:42:18.766765787 +0100 @@ -0,0 +1,15 @@ +// PR c++/82799 +// { dg-do compile } +// { dg-options "-Wunused-but-set-variable" } + +enum E { b }; +struct C { + template <E> + int foo () + { + const bool i = 0; // { dg-bogus "set but not used" } + const int r = i ? 7 : 9; + return r; + } + void bar () { foo <b> (); } +}; --- gcc/testsuite/g++.dg/warn/Wunused-var-29.C.jj 2018-01-05 16:45:59.576857460 +0100 +++ gcc/testsuite/g++.dg/warn/Wunused-var-29.C 2018-01-05 16:45:42.956850557 +0100 @@ -0,0 +1,10 @@ +// PR c++/83690 +// { dg-do compile { target c++11 } } +// { dg-options "-Wunused-but-set-variable" } + +void +foo () +{ + constexpr bool foo = true; // { dg-bogus "set but not used" } + static_assert (foo, "foo"); +} Jakub