This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

value computed is not used warnings


   void f() { ({ (void) 0; }); }

We'll currently give a warning for this function with -Wall.
Given that this ocurrs rather a lot during a bootstrap, I'd
like to fix it.

The first segment of this patch silences the warning in a rather
heavy-handed way.  The second segment of the patch makes the code
calling warn_if_unused_value look like the other two instances
in the c and c++ front ends.

Comments?


r~


Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.157
diff -c -p -d -r1.157 c-common.c
*** c-common.c	2000/09/19 03:26:10	1.157
--- c-common.c	2000/09/19 08:38:22
*************** c_expand_expr_stmt (expr)
*** 2877,2882 ****
--- 2877,2888 ----
  
    last_expr_type = TREE_TYPE (expr); 
    add_stmt (build_stmt (EXPR_STMT, expr));
+ 
+   /* ??? Statement expressions appear to stmt.c to be widgets without
+      (apparently) interesting side effects that is not used, so we get
+      a warning.  Since EXPR_STMT isn't a generic tree node, we can't
+      special case things there.  So just mark the thing used here.  */
+   TREE_USED (expr) = 1;
  }
  
  /* Validate the expression after `case' and apply default promotions.  */
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 08:38:22
*************** 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);
      }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]