This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: value computed is not used warnings
On Tue, Sep 19, 2000 at 02:02:37AM -0700, Mark Mitchell wrote:
> Actually, I think maybe the right fix is to have warn_if_unused_value
> ignore `void' expressions. It already tries hard to avoid things that
> are explicitly cast to `void' and functions that return `void', but it
> doesn't deal with values that are magically `void' like a `void'
> STMT_EXPR. Does that sound like a better fix?
Yes.
r~
* 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.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.168
diff -c -p -d -r1.168 stmt.c
*** stmt.c 2000/09/17 12:45:51 1.168
--- stmt.c 2000/09/19 13:36:50
*************** expand_expr_stmt (exp)
*** 1908,1919 ****
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");
else if (warn_unused_value)
warn_if_unused_value (exp);
}
--- 1908,1921 ----
except inside a ({...}) where they may be useful. */
if (expr_stmts_for_value == 0 && exp != error_mark_node)
{
! 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);
}
*************** warn_if_unused_value (exp)
*** 1978,1983 ****
--- 1980,1991 ----
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:
*************** warn_if_unused_value (exp)
*** 2023,2031 ****
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;
--- 2031,2036 ----