[PATCH] c, c++: Fix up -Wunused-value on COMPLEX_EXPRs [PR97748]
Jakub Jelinek
jakub@redhat.com
Tue Nov 10 08:48:15 GMT 2020
On Mon, Nov 09, 2020 at 10:34:00PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Mon, Nov 09, 2020 at 02:35:58PM -0500, Jason Merrill wrote:
> > How about calling warn_if_unused_value instead of the new
> > warn_if_unused_value_p?
>
> That seems to work if I just replace the warning_at call with
> warn_if_unused_value call (at least no regression in check-c++-all and
> libstdc++ testsuite).
> Initially I've tried just calling warn_if_unused_value without the NOP_EXPR
> stripping and code/tclass checks, but that regressed a few tests, e.g.
> g++.dg/warn/Wunused-14.C or c-c++-common/Wunused-var-9.c or 3 lines
> in the new test, e.g. because STATEMENT_LIST or CLEANUP_POINT_EXPRs would
> make it through and resulted in bogus warnings.
Bootstrapped/regtested on x86_64-linux and i686-linux successfully now.
If we wanted to simplify, I think the && !(code == ....) part could be
dropped too, i.e. just
if (tclass == tcc_comparison
|| tclass == tcc_unary
|| tclass == tcc_binary
|| code == VEC_PERM_EXPR
|| code == VEC_COND_EXPR)
warn_if_unused_value (e, loc);
because warn_if_unused_value already returns false on those codes.
> + enum tree_code code = TREE_CODE (e);
> + enum tree_code_class tclass = TREE_CODE_CLASS (code);
> + if (tclass == tcc_comparison
> + || tclass == tcc_unary
> + || (tclass == tcc_binary
> + && !(code == MODIFY_EXPR
> + || code == INIT_EXPR
> + || code == PREDECREMENT_EXPR
> + || code == PREINCREMENT_EXPR
> + || code == POSTDECREMENT_EXPR
> + || code == POSTINCREMENT_EXPR))
> + || code == VEC_PERM_EXPR
> + || code == VEC_COND_EXPR)
> + warn_if_unused_value (e, loc);
> }
> }
> expr = build1 (CONVERT_EXPR, void_type_node, expr);
Jakub
More information about the Gcc-patches
mailing list