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]
Other format: [Raw text]

Re: [PATCH] Fix C++ -Wno-div-by-zero


On Tue, 31 Jan 2006, Dirk Mueller wrote:

> 2006-01-31  Dirk Mueller  <dmueller@suse.com>
> 	
> 	* c.opt: Remove Var(warn_div_by_zero).
> 	* c-opts.c: Remove dead OPT_Wdiv_by_zero case.
> 
> 	* typeck.c: Annotate division by zero warnings so
> 	that -Wno-div-by-zero works correctly.

You need to add a testcase to the testsuite verifying that 
-Wno-div-by-zero works for C++ (and one that the default is -Wdiv-by-zero 
if there isn't such a test already for C++, so that the testsuite 
demonstrates that -Wno-div-by-zero does have an effect).

> @@ -2991,9 +2991,9 @@ build_binary_op (enum tree_code code, tr
>      case TRUNC_MOD_EXPR:
>      case FLOOR_MOD_EXPR:
>        if (code1 == INTEGER_TYPE && integer_zerop (op1))
> -	warning (0, "division by zero in %<%E %% 0%>", op0);
> +	warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0%>", op0);
>        else if (code1 == REAL_TYPE && real_zerop (op1))
> -	warning (0, "division by zero in %<%E %% 0.%>", op0);
> +	warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0.%>", op0);

There's a difference here from the C behavior: the C front end doesn't 
warn for division by a floating point zero constant (although it warns for 
division of a floating point value by an integer zero) since explicit 
division by 0.0 is used as a way of generating Inf and NaN.  (Not a 
problem with this patch, since it's a pre-existing condition.)

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


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