Hi! The recent cp_build_modify_expr change broke the following testcase, we now complain that b is set but not used. The problem is that when rhs has side-effects, stabilize_expr returns a temporary (+ creates a TARGET_EXPR), which means that mark_exp_read isn't actually called on the original RHS expression.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-08-23 Jakub Jelinek <ja...@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. * g++.dg/warn/Wunused-var-16.C: New test. --- gcc/cp/typeck.c.jj 2011-08-18 08:35:38.000000000 +0200 +++ gcc/cp/typeck.c 2011-08-23 14:36:42.000000000 +0200 @@ -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, --- gcc/testsuite/g++.dg/warn/Wunused-var-16.C.jj 2011-08-23 14:37:31.000000000 +0200 +++ gcc/testsuite/g++.dg/warn/Wunused-var-16.C 2011-08-23 14:37:19.000000000 +0200 @@ -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; +} Jakub