diff options
author | Le-Chun Wu <lcwu@google.com> | 2009-04-15 17:55:50 +0000 |
---|---|---|
committer | Le-Chun Wu <lcwu@gcc.gnu.org> | 2009-04-15 17:55:50 +0000 |
commit | 041d7a2796d57d61a45c0a2e325ba626d578ab3f (patch) | |
tree | 1fcdb0340acf7d5d040d772569c97b16879b29e4 /gcc | |
parent | 2470b601067bff888ed5afc280a174970db1a242 (diff) | |
download | gcc-041d7a2796d57d61a45c0a2e325ba626d578ab3f.zip gcc-041d7a2796d57d61a45c0a2e325ba626d578ab3f.tar.gz gcc-041d7a2796d57d61a45c0a2e325ba626d578ab3f.tar.bz2 |
re PR c++/39551 (C++ frontend not warn about unused dereference operator with -Wunused-value)
PR c++/39551
* gcc/cp/call.c (build_over_call): Set TREE_NO_WARNING on the
compiler-generated INDIRECT_REF expression.
* gcc/cp/cvt.c (convert_to_void): Emit warning when stripping off
INDIRECT_REF.
* gcc/testsuite/g++.dg/warn/Wunused-13.C: New testcase.
From-SVN: r146132
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/call.c | 1 | ||||
-rw-r--r-- | gcc/cp/cvt.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wunused-13.C | 7 |
5 files changed, 35 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index aa0ef54..0cd3460 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2009-04-15 Le-Chun Wu <lcwu@google.com> + + PR c++/39551 + * call.c (build_over_call): Set TREE_NO_WARNING on the + compiler-generated INDIRECT_REF expression. + * cvt.c (convert_to_void): Emit warning when stripping off + INDIRECT_REF. + 2009-04-14 Diego Novillo <dnovillo@google.com> * parser.c (cp_parser_type_specifier_seq): Move call to diff --git a/gcc/cp/call.c b/gcc/cp/call.c index ef7c045..f6c24b6 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5419,6 +5419,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (test) t = build3 (COND_EXPR, TREE_TYPE (t), test, arg0, t); val = cp_build_indirect_ref (t, 0, complain); + TREE_NO_WARNING (val) = 1; } return val; diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index fed4ab2..5032f1c 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -870,7 +870,20 @@ convert_to_void (tree expr, const char *implicit, tsubst_flags_t complain) implicit ? implicit : "void context"); } if (is_reference || !is_volatile || !is_complete || TREE_ADDRESSABLE (type)) - expr = TREE_OPERAND (expr, 0); + { + /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF + operation is stripped off. Note that we don't warn about + - an expression with TREE_NO_WARNING set. (For an example of + such expressions, see build_over_call in call.c.) + - automatic dereferencing of references, since the user cannot + control it. (See also warn_if_unused_value() in stmt.c.) */ + if (warn_unused_value + && (complain & tf_warning) + && !TREE_NO_WARNING (expr) + && !is_reference) + warning (OPT_Wunused_value, "value computed is not used"); + expr = TREE_OPERAND (expr, 0); + } break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ffcd888..0096410 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-15 Le-Chun Wu <lcwu@google.com> + + PR c++/39551 + * g++.dg/warn/Wunused-13.C: New testcase. + 2009-04-15 Ian Lance Taylor <iant@google.com> * gcc.dg/Wenum-compare-1.c: New testcase. diff --git a/gcc/testsuite/g++.dg/warn/Wunused-13.C b/gcc/testsuite/g++.dg/warn/Wunused-13.C new file mode 100644 index 0000000..d0eae11 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-13.C @@ -0,0 +1,7 @@ +// Test whether -Wunused handles effectless indirect_ref operation ('*'). +// { dg-do compile } +// { dg-options "-Wunused" } + +void Foo(int* x) { + *x++; // { dg-warning "value computed is not used" } +} |