Another caller of constant_value_1 that needs to handle calling
mark_rvalue_use now that cv1 doesn't.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit a8bc011a19fdb684c60cf4727d6a93ad2886d7ea
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Jan 29 09:16:05 2018 -0500

            PR c++/83942 - wrong unused warning with static_cast.
    
            * cvt.c (ocp_convert): Call mark_rvalue_use.

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<int>(e);
+}

Reply via email to