re PR c++/50158 (invalid 'variable set but not used' warning (boolean used as an...
authorJakub Jelinek <jakub@redhat.com>
Tue, 23 Aug 2011 15:53:18 +0000 (17:53 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 23 Aug 2011 15:53:18 +0000 (17:53 +0200)
PR c++/50158
* typeck.c (cp_build_modify_expr): Call mark_rvalue_use on rhs
if it has side-effects and needs to be preevaluated.

* g++.dg/warn/Wunused-var-16.C: New test.

From-SVN: r177992

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-var-16.C [new file with mode: 0644]

index 5ebab87fcfa55a09f5304d5af9671f07f9a2d63a..39f1d310be4e85ab62fbf18c8a08deaa10193eb8 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/50158
+       * typeck.c (cp_build_modify_expr): Call mark_rvalue_use on rhs
+       if it has side-effects and needs to be preevaluated.
+
 2011-08-23  Siddhesh Poyarekar  <siddhesh.poyarekar@gmail.com>
 
        PR c++/50055
index a1f67613adcaaeba8bc77fa972c8e1118c08731d..4c130eee9246c80a6d5ec8ae9dec61be94ee34c7 100644 (file)
@@ -6692,6 +6692,8 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
             side effect associated with any single compound assignment
             operator. -- end note ]  */
          lhs = stabilize_reference (lhs);
+         if (TREE_SIDE_EFFECTS (rhs))
+           rhs = mark_rvalue_use (rhs);
          rhs = stabilize_expr (rhs, &init);
          newrhs = cp_build_binary_op (input_location,
                                       modifycode, lhs, rhs,
index 5eb38dec77a8a9f743ce1024b3afaf31ce2c0171..e3c521cd143afaee6e5da0cb16dc126c9778d2a6 100644 (file)
@@ -1,5 +1,8 @@
 2011-08-23  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/50158
+       * g++.dg/warn/Wunused-var-16.C: New test.
+
        PR middle-end/50161
        * gcc.dg/pr50161.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-16.C b/gcc/testsuite/g++.dg/warn/Wunused-var-16.C
new file mode 100644 (file)
index 0000000..070ce44
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/50158
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+int bar (int);
+
+int
+foo (int a)
+{
+  int b[] = { a, -a };
+  a += b[bar (a) < a];
+  return a;
+}