*Ping* patch, fortran] Warn about constant integer divisions
Harald Anlauf
anlauf@gmx.de
Wed Jun 24 20:22:00 GMT 2015
Steve,
I do not see any check on the remainder of the integer division.
A truncation warning is pointless for expressions like 4/2 or
n*(n+1)/2 with n an integer parameter.
I use similar expressions for static decompositions or blocking
that I am afraid would produce warnings in several places.
Just tell me what the option would be to turn the warning off.
After all, we're not quiche eaters. :)
Harald
On 06/23/15 23:00, Steve Kargl wrote:
> 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.
>
More information about the Fortran
mailing list