Hello world,

the attached patch emits a warning for constant integer division.
While correct according to the standard, I cannot really think
of a legitimate reason why people would want to write 3/5 where
they could have written 0 , so my preference would be to put
this under -Wconversion (like in the attached patch).

However, I am open to discussion on that.  It is easy enough to
change.

Regression-tested.  Opinions?  Comments?  Would somebody rather
have -Wconversion-extra?  OK for trunk?

Regards

        Thomas
Index: arith.c
===================================================================
--- arith.c	(Revision 224450)
+++ arith.c	(Arbeitskopie)
@@ -733,6 +733,15 @@ gfc_arith_divide (gfc_expr *op1, gfc_expr *op2, gf
 
       mpz_tdiv_q (result->value.integer, op1->value.integer,
 		  op2->value.integer);
+
+      if (warn_conversion)
+	{
+	  char *p;
+	  p = mpz_get_str (NULL, 10, result->value.integer);
+	  gfc_warning_now (OPT_Wconversion, "Integer division simplifies "
+			   "to constant %qs at %L", p, &op1->where);
+	  free (p);
+	}
       break;
 
     case BT_REAL:
! { dg-do compile }
! { dg-options "-Wconversion" }
program main
  print *, 3/5 ! { dg-warning "Integer division simplifies to constant" }
end program main

Reply via email to