This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix -Wunused-but-set-variable false positives with cast to floating (PR c++/55643)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 11 Dec 2012 19:25:20 +0100
- Subject: [C++ PATCH] Fix -Wunused-but-set-variable false positives with cast to floating (PR c++/55643)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
When casting ints to other ints, CASE_CONVERT in mark_exp_read handles that
case, but for FLOAT_EXPR it doesn't. I've tried other static casts, but
haven't found anything else that would fail similarly.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7?
2012-12-11 Jakub Jelinek <jakub@redhat.com>
PR c++/55643
* expr.c (mark_exp_read): Handle FLOAT_EXPR similarly to NOP_EXPR.
* g++.dg/warn/Wunused-var-19.C: New test.
--- gcc/cp/expr.c.jj 2010-12-02 11:51:22.000000000 +0100
+++ gcc/cp/expr.c 2012-12-11 08:51:53.008992474 +0100
@@ -131,6 +131,7 @@ mark_exp_read (tree exp)
CASE_CONVERT:
case ADDR_EXPR:
case INDIRECT_REF:
+ case FLOAT_EXPR:
mark_exp_read (TREE_OPERAND (exp, 0));
break;
case COMPOUND_EXPR:
--- gcc/testsuite/g++.dg/warn/Wunused-var-19.C.jj 2012-12-11 08:54:47.600958580 +0100
+++ gcc/testsuite/g++.dg/warn/Wunused-var-19.C 2012-12-11 08:53:20.000000000 +0100
@@ -0,0 +1,26 @@
+// PR c++/55643
+// { dg-do compile }
+// { dg-options "-std=c++11 -Wunused" }
+
+enum class E { e = 123 };
+
+int
+foo ()
+{
+ E x = E::e;
+ return (double) x;
+}
+
+int
+bar ()
+{
+ E x = E::e;
+ return (long double) x;
+}
+
+int
+baz ()
+{
+ E x = E::e;
+ return (float) x;
+}
Jakub