diff options
author | Jakub Jelinek <jakub@redhat.com> | 2010-05-11 20:12:28 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2010-05-11 20:12:28 +0200 |
commit | 056928b248b7e3f879c2b3ac4be935e67ad3a09a (patch) | |
tree | 89061f89197477311627b0ab6424fa6ee67aaf52 /gcc/cp | |
parent | edf86ec148f98f12a16ba9b2a26b0b66b6078c50 (diff) | |
download | gcc-056928b248b7e3f879c2b3ac4be935e67ad3a09a.zip gcc-056928b248b7e3f879c2b3ac4be935e67ad3a09a.tar.gz gcc-056928b248b7e3f879c2b3ac4be935e67ad3a09a.tar.bz2 |
re PR c++/44062 ((void)var; doesn't prevent 'set but not used' warning)
PR c++/44062
* c-parser.c (c_parser_expression): Mark LHS of a comma
expression as read if it is a decl, handled component or
COMPOUND_EXPR with that on the RHS.
* c-typeck.c (c_process_expr_stmt): Mark RHS of COMPOUND_EXPR
if it is a decl or handled component.
* semantics.c (finish_expr_stmt): Don't call mark_exp_read here...
* cvt.c (convert_to_void): ... but here. If expr is a COMPOUND_EXPR,
look at its second operand.
* c-c++-common/Wunused-var-7.c: New test.
* g++.dg/warn/Wunused-var-9.C: New test.
From-SVN: r159286
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/cvt.c | 16 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 9 |
3 files changed, 23 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 31749dd..597f8f1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2010-05-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/44062 + * semantics.c (finish_expr_stmt): Don't call mark_exp_read here... + * cvt.c (convert_to_void): ... but here. If expr is a COMPOUND_EXPR, + look at its second operand. + 2010-05-10 Jason Merrill <jason@redhat.com> PR c++/44017 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index b357084..efef5c2 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1,6 +1,6 @@ /* Language-level data type conversion for GNU C++. Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Hacked by Michael Tiemann (tiemann@cygnus.com) @@ -822,9 +822,23 @@ ocp_convert (tree type, tree expr, int convtype, int flags) tree convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain) { + tree exprv; + if (expr == error_mark_node || TREE_TYPE (expr) == error_mark_node) return error_mark_node; + + exprv = expr; + while (TREE_CODE (exprv) == COMPOUND_EXPR) + exprv = TREE_OPERAND (exprv, 1); + if (DECL_P (exprv) || handled_component_p (exprv)) + /* 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 + to avoid some warnings when + -Wunused-but-set-{variable,parameter} is in effect. */ + mark_exp_read (exprv); + if (!TREE_TYPE (expr)) return expr; if (invalid_nonstatic_memfn_p (expr, complain)) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index cbbcf96..135de46 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4,7 +4,7 @@ and during the instantiation of template functions. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009 Free Software Foundation, Inc. + 2008, 2009, 2010 Free Software Foundation, Inc. Written by Mark Mitchell (mmitchell@usa.net) based on code found formerly in parse.y and pt.c. @@ -610,13 +610,6 @@ finish_expr_stmt (tree expr) { if (warn_sequence_point) verify_sequence_points (expr); - if (TREE_CODE (expr) != MODIFY_EXPR) - /* 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 - to avoid some warnings when - -Wunused-but-set-{variable,parameter} is in effect. */ - mark_exp_read (expr); expr = convert_to_void (expr, "statement", tf_warning_or_error); } else if (!type_dependent_expression_p (expr)) |