*Ping* patch, fortran] Warn about constant integer divisions
Steve Kargl
sgk@troutmask.apl.washington.edu
Tue Jun 23 21:00:00 GMT 2015
On Tue, Jun 23, 2015 at 08:45:35PM +0200, Harald Anlauf wrote:
>
> I would not be happy to get a warning for integer division with
> -Wconversion, which is perfectly valid and normal code.
>
> Adding this feature to -Wconversion would make this flag unusable for me.
>
> If you searched for a more suitable flag, I'd recommend -Wsurprising.
>
Have you actually read the patch and understand what it does?
It is a compile time warning when constant-folding occurs. It
is not a runtime error. Do really have a large amount of code
that initializes variables via integer division?
program a
integer i,j
real x
x = 3 / 5 ! warning. Programming error? x = 0.666 or 0?
i = 3 / 5 ! no warning. fancy way to init i to 0?
i = 4
x = x / i ! no warning
j = i / 3 ! no warning
i = 5/3 ! warning. fancy way to init j to 1?
end program a
For the record, when I was coding up a variable-order
runge-kutta algorithm, I actually made the mistake in
one of 33 named constants of doing exactly what this
warning is meant to catch. That code now does
something along the lines of
real(knd), parameter :: b21 = real( 1, knd) / 5 ! 1/5
real(knd), parameter :: b31 = real( 3, knd) / 40 ! 3/40
real(knd), parameter :: b32 = real( 9, knd) / 40 ! 9/40
real(knd), parameter :: b41 = real( 3, knd) / 10 ! 3/10
real(knd), parameter :: b42 = -real( 9, knd) / 10 ! -9/10
Thomas, please following Janne's suggestion of adding a new
-W option (I'll suggest -Winteger-division) and add this
to -Wall.
--
Steve
More information about the Fortran
mailing list