Patchwork [C++] Fix -Wunused-but-set-variable false positives with cast to floating (PR c++/55643)

login
register
mail settings
Submitter Jakub Jelinek
Date Dec. 11, 2012, 6:25 p.m.
Message ID <20121211182520.GS2315@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/205286/
State New
Headers show

Comments

Jakub Jelinek - Dec. 11, 2012, 6:25 p.m.
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.


	Jakub
Jason Merrill - Dec. 11, 2012, 6:59 p.m.
OK.

Jason

Patch

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