public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/83942, wrong -Wunused-but-set-var warning with static_cast
@ 2018-01-29 18:13 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2018-01-29 18:13 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 150 bytes --]

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.

[-- Attachment #2: 83942.diff --]
[-- Type: text/plain, Size: 1145 bytes --]

commit a8bc011a19fdb684c60cf4727d6a93ad2886d7ea
Author: Jason Merrill <jason@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);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-01-29 15:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-29 18:13 C++ PATCH for c++/83942, wrong -Wunused-but-set-var warning with static_cast Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).