@@ -6692,6 +6692,8 @@ cp_build_modify_expr (tree lhs, enum tre
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,
@@ -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;
+}