Commit d84686d1 by Jakub Jelinek Committed by Jakub Jelinek

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
parent 026698d2
2010-06-07 Jakub Jelinek <jakub@redhat.com> 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 PR c++/44443
* decl.c (initialize_local_var): If TREE_USED is set on the type, * decl.c (initialize_local_var): If TREE_USED is set on the type,
set also DECL_READ_P on the decl. set also DECL_READ_P on the decl.
......
...@@ -834,7 +834,9 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain) ...@@ -834,7 +834,9 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain)
while (TREE_CODE (exprv) == COMPOUND_EXPR) while (TREE_CODE (exprv) == COMPOUND_EXPR)
exprv = TREE_OPERAND (exprv, 1); 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 /* Expr is not being 'used' here, otherwise we whould have
called mark_{rl}value_use use here, which would have in turn called mark_{rl}value_use use here, which would have in turn
called mark_exp_read. Rather, we call mark_exp_read directly called mark_exp_read. Rather, we call mark_exp_read directly
......
/* Convert language-specific tree expression to rtl instructions, /* Convert language-specific tree expression to rtl instructions,
for GNU compiler. for GNU compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 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. This file is part of GCC.
...@@ -132,6 +132,7 @@ mark_exp_read (tree exp) ...@@ -132,6 +132,7 @@ mark_exp_read (tree exp)
case IMAGPART_EXPR: case IMAGPART_EXPR:
CASE_CONVERT: CASE_CONVERT:
case ADDR_EXPR: case ADDR_EXPR:
case INDIRECT_REF:
mark_exp_read (TREE_OPERAND (exp, 0)); mark_exp_read (TREE_OPERAND (exp, 0));
break; break;
case COMPOUND_EXPR: case COMPOUND_EXPR:
......
2010-06-07 Jakub Jelinek <jakub@redhat.com> 2010-06-07 Jakub Jelinek <jakub@redhat.com>
PR c++/44444
* g++.dg/warn/Wunused-var-12.C: New test.
PR c++/44443 PR c++/44443
* c-c++-common/Wunused-var-11.c: New test. * c-c++-common/Wunused-var-11.c: New test.
......
// 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" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment