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
This commit is contained in:
Jakub Jelinek 2011-08-23 17:53:18 +02:00 committed by Jakub Jelinek
parent e2f0083772
commit 09e640b34d
4 changed files with 24 additions and 0 deletions

View 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

View 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,

View 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.

View File

@ -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;
}