mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
c++: missing -Wunused-value for !<expr> [PR114104]
Here we're neglecting to issue a -Wunused-value warning for suitable ! operator expressions, and in turn for != operator expressions that are rewritten as !(x == y), only because we don't call warn_if_unused_value on TRUTH_NOT_EXPR since its class is tcc_expression. This patch makes us also consider warning for TRUTH_NOT_EXPR and also for ADDR_EXPR. PR c++/114104 gcc/cp/ChangeLog: * cvt.cc (convert_to_void): Call warn_if_unused_value for TRUTH_NOT_EXPR and ADDR_EXPR as well. gcc/testsuite/ChangeLog: * g++.dg/warn/Wunused-20.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
parent
313afcfdab
commit
144b6099cd
@ -1664,6 +1664,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
|
||||
if (tclass == tcc_comparison
|
||||
|| tclass == tcc_unary
|
||||
|| tclass == tcc_binary
|
||||
|| code == TRUTH_NOT_EXPR
|
||||
|| code == ADDR_EXPR
|
||||
|| code == VEC_PERM_EXPR
|
||||
|| code == VEC_COND_EXPR)
|
||||
warn_if_unused_value (e, loc);
|
||||
|
19
gcc/testsuite/g++.dg/warn/Wunused-20.C
Normal file
19
gcc/testsuite/g++.dg/warn/Wunused-20.C
Normal file
@ -0,0 +1,19 @@
|
||||
// PR c++/114104
|
||||
// { dg-additional-options "-Wunused-value" }
|
||||
|
||||
bool f();
|
||||
struct A { int i; };
|
||||
A& g();
|
||||
|
||||
void h() {
|
||||
!f(); // { dg-warning "value computed is not used" }
|
||||
&g().i; // { dg-warning "value computed is not used" }
|
||||
}
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
[[nodiscard]] bool operator==(A&, int);
|
||||
|
||||
void h(A a) {
|
||||
a != 0; // { dg-warning "value computed is not used" "" { target c++20 } }
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user