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]

C++ PATCH: Consolidate division by zero warnings


Hi, 

I've noticed that the C and C++ frontends disagree about the "divison by zero" 
warning. The C frontend ignored it for real constants. Now the C++ frontend 
does too. 

Bootstrapped/regtested on i686-suse-linux. Ok for trunk?

2006-04-12  Dirk Mueller  <dmueller@suse.de>

        * typeck.c (build_binary_op): Don't warn about division
        by real constants.

        * g++.dg/warn/Wdiv-by-zero.C: Update testcase.

--- cp/typeck.c
+++ cp/typeck.c
@@ -3012,10 +3012,10 @@ build_binary_op (enum tree_code code, tr
 	  && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
 	      || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
 	{
+           /* Floating point division by zero is a legitimate way to obtain
+·             infinities and NaNs.  */
 	  if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1))
 	    warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0%>", op0);
-	  else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1))
-	    warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0.%>", op0);
 
 	  if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
 	    code0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));

--- testsuite/g++.dg/warn/Wdiv-by-zero.C
+++ testsuite/g++.dg/warn/Wdiv-by-zero.C
@@ -3,5 +3,7 @@ int breakme()
 {
   int x = 0;
   x /= 0;          // { dg-warning "division by" }
-  return x;
+
+  double z = 0.0 / 0.0;  // { dg-bogus "division by" }
+  return x + z;
 }


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