On Fri, Jan 26, 2024 at 11:38:01PM +0100, FX Coudert wrote:
> > Interesting example.
> > 
> > % gfcx -o z a.f90 &&  ./z
> > -128
> > % gfcx -o z -pedantic a.f90 && ./z
> > a.f90:5:20:
> > 
> >    5 |   data j /-128_int8/
> >      |                    1
> > Error: Integer too big for its kind at (1). This check can be disabled with 
> > the option ‘-fno-range-check’
> 
> That qualifies as a compiler bug, I think. Our documentation for -pedantic 
> states: “Issue warnings for uses of extensions to Fortran.” and "Valid 
> Fortran programs should compile properly with or without this option.”
> 
> The same is true of the following, which is also valid Fortran since 95 :
> 
>  use iso_fortran_env
>  implicit none
>  complex, parameter :: z = (-128_int8, -128_int8)
>  print *, z
>  end
> 
> Right now it fails to compile with -pedantic.
> 
> Or are they illegal because of how the range should be be symmetric? I can’t 
> quite find the language in the standard for that, actually. To me, they’re 
> valid signed-int-literal-constant.
> 

Symmetry comes from the definition of a model integer number
in 16.3.3 "Bit sequences as arguments to INT and REAL".  If
'i' and 'j' are INTEGER(1), then this leads to something like
'j = abs(i)' being comforming except if 'i = -128'.

As far as literal constants, one has from Fortran 2023 p. 66

R707 signed-int-literal-constant  is [ sign ] int-literal-constant
R708 int-literal-constant         is digit-string [ _ kind-param ]
R709 kind-param                   is digit-string

R710 signed-digit-string  is [ sign ] digit-string
R711 digit-string         is digit [ digit ] ...
R712 sign                 is +
                          or -

I cannot find in the Standard any statement about the conversion
of a digit-string to an internal representation.  I suspect it
depends on the path through the compiler.  In assignments, the
signed-digit-string is likely handled as a unary operator and
operand. 

-- 
Steve

Reply via email to