Hi,

I stumbled upon a Fortran quirk regarding the ranges for integers. The standard 
stipulates that the ranges be symmetric even though as we know two's complement 
signed integers have asymmetrical ranges, e.g. int8 kind can vary between -128 
and 127.

This is sure to cause confusion as for example the following program does not 
compile:

```
program main
  use iso_fortran_env
  implicit none
  print *, -128_int8
end program
```

GFortran 13.2.0 provides the error message

Error: Integer too big for its kind at (1). This check can be disabled with the 
option '-fno-range-check'
 
While a workaround to disable the range check is provided, the error message is 
a bit misleading. For one, the number is too small for the int8 number model. 
For the second, it is not obvious to the lay why removing the kind literal 
leads to a clean compile.

Codewise the topic has been discussed in PRs 13490 and 17912, and I think the 
current implementation is correct. What could be improved are the pages 
https://gcc.gnu.org/bugs/ and the above error message. 

I would like to propose that the error message should hint more towards the 
root cause. Something along the lines of: 'Out of range integer for its 
selected kind at (1). This check can be disabled with the option 
'-fno-range-check'.

Secondly, I think this quirk could be a good candidate to the known bugs 
section of your website.

I tried to file a bug / craft a PR but access to your repos is a bit limited at 
this point, so I decided to write this message as my 2 cents. 

Anyway, thanks for your good work! I can also volunteer to help you with this 
or some other tasks. Haven't done it before but would be interesting to try it 
out.

--
Best regards / Ystävällisesti
Elias Toivanen
elias.a.toiva...@gmail.com


Reply via email to