OSDN Git Service

PR c++/50158
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 23 Aug 2011 15:53:18 +0000 (15:53 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 23 Aug 2011 15:53:18 +0000 (15:53 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177992 138bc75d-0d04-0410-961f-82ee72b054a4

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 5ebab87..39f1d31 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 a1f6761..4c130ee 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 5eb38de..e3c521c 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;
+}