re PR c++/44444 (-Wunused-but-set-variable problem with field references)

PR c++/44444
	* expr.c (mark_exp_read): Handle INDIRECT_REF.
	* cvt.c (convert_to_void): Handle INDIRECT_REF like
	handled_component_p.

	* g++.dg/warn/Wunused-var-12.C: New test.

From-SVN: r160388
This commit is contained in:
Jakub Jelinek 2010-06-07 19:50:10 +02:00 committed by Jakub Jelinek
parent 026698d28e
commit d84686d14a
5 changed files with 49 additions and 2 deletions

View File

@ -1,5 +1,10 @@
2010-06-07 Jakub Jelinek <jakub@redhat.com>
PR c++/44444
* expr.c (mark_exp_read): Handle INDIRECT_REF.
* cvt.c (convert_to_void): Handle INDIRECT_REF like
handled_component_p.
PR c++/44443
* decl.c (initialize_local_var): If TREE_USED is set on the type,
set also DECL_READ_P on the decl.

View File

@ -834,7 +834,9 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain)
while (TREE_CODE (exprv) == COMPOUND_EXPR)
exprv = TREE_OPERAND (exprv, 1);
if (DECL_P (exprv) || handled_component_p (exprv))
if (DECL_P (exprv)
|| handled_component_p (exprv)
|| TREE_CODE (exprv) == INDIRECT_REF)
/* Expr is not being 'used' here, otherwise we whould have
called mark_{rl}value_use use here, which would have in turn
called mark_exp_read. Rather, we call mark_exp_read directly

View File

@ -1,7 +1,7 @@
/* Convert language-specific tree expression to rtl instructions,
for GNU compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
2000, 2001, 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
This file is part of GCC.
@ -132,6 +132,7 @@ mark_exp_read (tree exp)
case IMAGPART_EXPR:
CASE_CONVERT:
case ADDR_EXPR:
case INDIRECT_REF:
mark_exp_read (TREE_OPERAND (exp, 0));
break;
case COMPOUND_EXPR:

View File

@ -1,5 +1,8 @@
2010-06-07 Jakub Jelinek <jakub@redhat.com>
PR c++/44444
* g++.dg/warn/Wunused-var-12.C: New test.
PR c++/44443
* c-c++-common/Wunused-var-11.c: New test.

View File

@ -0,0 +1,36 @@
// PR c++/44444
// { dg-do compile }
// { dg-options "-Wunused" }
struct S
{
const int &u;
const int &v;
S (const int &a, const int &b) : u(a), v(b) { }
};
bool
f1 ()
{
bool t = false;
S z = S (1, 2);
t |= z.u == 1;
t |= z.v == 2;
return t;
}
void
f2 ()
{
S z = S (1, 2);
z.u; // { dg-warning "no effect" }
}
int i;
void
f3 ()
{
S z = S (1, 2);
i++, z.u; // { dg-warning "no effect" }
}