From 82be290b3b9450897c1f328f07ffa71839f4582c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 29 Jan 2018 11:56:28 -0500 Subject: [PATCH] PR c++/83942 - wrong unused warning with static_cast. * cvt.c (ocp_convert): Call mark_rvalue_use. From-SVN: r257155 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/cvt.c | 5 ++++- gcc/testsuite/g++.dg/warn/Wunused-var30.C | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var30.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c526645e380..90e8ff18203 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-01-29 Jason Merrill + + PR c++/83942 - wrong unused warning with static_cast. + * cvt.c (ocp_convert): Call mark_rvalue_use. + 2018-01-26 Jason Merrill PR c++/83956 - wrong dtor error with anonymous union diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 7ed2aad6136..3ab3e2e2b40 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -691,7 +691,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags, /* FIXME remove when moving to c_fully_fold model. */ if (!CLASS_TYPE_P (type)) - e = scalar_constant_value (e); + { + e = mark_rvalue_use (e); + e = scalar_constant_value (e); + } if (error_operand_p (e)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var30.C b/gcc/testsuite/g++.dg/warn/Wunused-var30.C new file mode 100644 index 00000000000..f3f7f1ae5bb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var30.C @@ -0,0 +1,9 @@ +// PR c++/83942 +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wall" } + +enum class E { E1 }; +int main() { + E const e = E::E1; + return static_cast(e); +} -- 2.30.2