This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -Wunused-value (PR c/39889)


Hi!

The following testcase incorrectly warns that value computed is not used
in 4.4, because warn_if_unused_value doesn't handle NON_LVALUE_EXPR.

Fixed thusly, bootstrapped/regtested on x86_64-linux.
While this doesn't warn on the trunk since Joseph's big C FE changes,
I still think even on the trunk warn_if_unused_value should handle
NON_LVALUE_EXPR, so ok for 4.4 and trunk?

2009-04-24  Jakub Jelinek  <jakub@redhat.com>

	PR c/39889
	* stmt.c (warn_if_unused_value): Look through NON_LVALUE_EXPR.

	* gcc.dg/Wunused-value-3.c: New test.

--- gcc/stmt.c.jj	2009-03-28 18:11:43.000000000 +0100
+++ gcc/stmt.c	2009-04-24 23:24:49.000000000 +0200
@@ -1418,6 +1418,7 @@ warn_if_unused_value (const_tree exp, lo
       goto restart;
 
     case SAVE_EXPR:
+    case NON_LVALUE_EXPR:
       exp = TREE_OPERAND (exp, 0);
       goto restart;
 
--- gcc/testsuite/gcc.dg/Wunused-value-3.c.jj	2009-04-24 23:26:18.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-value-3.c	2009-04-24 23:26:01.000000000 +0200
@@ -0,0 +1,9 @@
+/* PR c/39889 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-value" } */
+
+int x;
+int foo (void)
+{
+  return (1 ? x = 0 : (void) 0), 0; /* { dg-bogus "value computed is not used" } */
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]