From 09e640b34df2fd4f0413f6984194606e97191292 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 23 Aug 2011 17:53:18 +0200 Subject: [PATCH] re PR c++/50158 (invalid 'variable set but not used' warning (boolean used as an index to an array)) 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 | 6 ++++++ gcc/cp/typeck.c | 2 ++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/warn/Wunused-var-16.C | 13 +++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-16.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5ebab87fcfa..39f1d310be4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-08-23 Jakub Jelinek + + 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 PR c++/50055 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a1f67613adc..4c130eee924 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5eb38dec77a..e3c521cd143 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-08-23 Jakub Jelinek + 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 index 00000000000..070ce446bba --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-16.C @@ -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; +} -- 2.30.2