2000-09-19 Richard Henderson <rth@cygnus.com>
+ * stmt.c (expand_expr_stmt): Only call warn_if_unused_value
+ if the tree has side effects.
+ (warn_if_unused_value): Do not warn about void constructs.
+
* c-decl.c (poplevel): Invoke warn_about_unused_variables.
* unroll.c (copy_loop_body): Update LABEL_NUSES before
except inside a ({...}) where they may be useful. */
if (expr_stmts_for_value == 0 && exp != error_mark_node)
{
- if (! TREE_SIDE_EFFECTS (exp)
- && (extra_warnings || warn_unused_value)
- && !(TREE_CODE (exp) == CONVERT_EXPR
- && VOID_TYPE_P (TREE_TYPE (exp))))
- warning_with_file_and_line (emit_filename, emit_lineno,
- "statement with no effect");
+ if (! TREE_SIDE_EFFECTS (exp))
+ {
+ if ((extra_warnings || warn_unused_value)
+ && !(TREE_CODE (exp) == CONVERT_EXPR
+ && VOID_TYPE_P (TREE_TYPE (exp))))
+ warning_with_file_and_line (emit_filename, emit_lineno,
+ "statement with no effect");
+ }
else if (warn_unused_value)
warn_if_unused_value (exp);
}
if (TREE_USED (exp))
return 0;
+ /* Don't warn about void constructs. This includes casting to void,
+ void function calls, and statement expressions with a final cast
+ to void. */
+ if (VOID_TYPE_P (TREE_TYPE (exp)))
+ return 0;
+
switch (TREE_CODE (exp))
{
case PREINCREMENT_EXPR:
case NOP_EXPR:
case CONVERT_EXPR:
case NON_LVALUE_EXPR:
- /* Don't warn about values cast to void. */
- if (VOID_TYPE_P (TREE_TYPE (exp)))
- return 0;
/* Don't warn about conversions not explicit in the user's program. */
if (TREE_NO_UNUSED_WARNING (exp))
return 0;