j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

"j = -2147483648" should conform #267

Open klausler opened 2 years ago

klausler commented 2 years ago

The grammar of expressions is such that the "-2147483648" parses not as a signed-int-literal-constant (R707 in F'2018) but instead as an add-op (R1009) of "-" applied, with some layers of packaging that I can omit, to a primary (R1001) that is a literal-constant (R605) that is an (unsigned) int-literal-constant (R708). And for default integer on a 32-bit machine with two's-complement integers -- namely everywhere -- the int-literal-constant 2147483648 is not in the valid range of the type.

Many Fortran compilers accept -2147483648 as an expression. This usage is unambiguous and safe, and should not have to be an extension to the standard.

This problem exists with all kinds of two's-complement integers, of course; I'm using a specific type and value as a motivating example.