]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/83942 - wrong unused warning with static_cast.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Jan 2018 16:56:28 +0000 (16:56 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Jan 2018 16:56:28 +0000 (16:56 +0000)
* cvt.c (ocp_convert): Call mark_rvalue_use.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257155 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/testsuite/g++.dg/warn/Wunused-var30.C [new file with mode: 0644]

index c526645e380d3e5d53813dd2174e7755dc41fd22..90e8ff18203284ec04f94cf0843a86944b0a591b 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/83942 - wrong unused warning with static_cast.
+       * cvt.c (ocp_convert): Call mark_rvalue_use.
+
 2018-01-26  Jason Merrill  <jason@redhat.com>
 
        PR c++/83956 - wrong dtor error with anonymous union
index 7ed2aad613606c45ce1e4b6a985cf55a753bc3e3..3ab3e2e2b40f5bedc574fe93d272afe80f508750 100644 (file)
@@ -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 (file)
index 0000000..f3f7f1a
--- /dev/null
@@ -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);
+}