------- Comment #3 from jakub at gcc dot gnu dot org  2009-11-24 08:10 -------
-Wunused-variable is checking the TREE_USED flag, which is set quite early
during the parsing (in C FE build_external_ref, in C++ FE mark_used called from
finish_id_expression).  At that point the parser doesn't track whether it is
LHS of an assignment or RHS in a way that could be easily checked in those
routines unfortunately (and just setting a some parser flag e.g. around
lhs = c_parser_conditional_expression (parser, after);
in c_parser_expr_no_commas is insufficient, we want that only for the actual
LHS, but not other variables referenced in that, say in x[i] = 5; i must be
marked as used, etc.).  So implementing this isn't just a one-liner.

On the other side, I agree the warning is very useful in some cases, not so
much when var is only used on LHS where RHS has no side-effects, that is just
optimized out, but if an otherwise unused variable is initialized using some
expensive function call the user might find out that the call is just a waste
of time and remove it, even when it is not marked pure/const and thus the
compiler can't optimize it itself.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36390

Reply via email to