https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99561
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED CC| |kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to Michal Paszta from comment #0) > In this line of code: > > INTEGER(KIND=1) :: var8 = 257_2 > > we try to cast an integer of kind 2 (16 bits) onto an integer of kind 1 (8 > bits, value up to 256). This will result in a truncation of the value and is > allowed by the Fortran 2018 Standard, see Table 10.9, Fortran 2018 Standard. > The sentence preceding Table 10.9 and the table tell you what conversions are allowed and how the conversion is done via a built-in intrinsic subprogram. It does tell you anything about an out-of-range value. In fact, an INTEGER(KIND=1) entity has a range of [-128,127], so the value of 256 is still out-of-range. As you have found, gfortran offers a programmer a bullet to shoot their foot (i.e, the -fno-range-check option). On most (all?) targets supported by gfortran, you'll get two's complement wrap-around semantics. You do not get truncation, where I assume you mean that an out-of-range value is truncated to -128 or 127 as the situation would merit (e.g., var8 = 257_2 <-- huge(var8) = 127). As to the "no warning problem", you did not ask gfortran to generate warnings. You can use either the -Wall option or the -Wconversion option to get a warning when using the -fno-range-check option. %gfcx -o z -fno-range-check -Wall a.f90 a.f90:2:33: 2 | integer(1), parameter :: var8 = 257_2 | 1 Warning: Conversion from 'INTEGER(2)' to 'INTEGER(1)' at (1) [-Wconversion]