public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/83942, wrong -Wunused-but-set-var warning with static_cast
Date: Mon, 29 Jan 2018 18:13:00 -0000	[thread overview]
Message-ID: <CADzB+2kTe05D2Yd0MaMEhtcGMRREzkWmr3fzdO19CeDmSc2vnA@mail.gmail.com> (raw)

[-- 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);
+}

                 reply	other threads:[~2018-01-29 15:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADzB+2kTe05D2Yd0MaMEhtcGMRREzkWmr3fzdO19CeDmSc2vnA@mail.gmail.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).