https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99561
Bug ID: 99561 Summary: gfortran reports an error for a truncation that is permitted by the standard Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: michal.paszta at mobica dot com Target Milestone: --- 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. $ ~/gcc/trunk/bin/gfortran issue.f90 issue.f90:17:27: 17 | INTEGER(KIND=1) :: var8 = 257_2 | 1 Error: Arithmetic overflow converting INTEGER(2) to INTEGER(1) at (1). This check can be disabled with the option ‘-fno-range-check’ We believe the operation should be allowed. It could warn the programmer about the truncation, but should not prevent a successful compilation. The obvious workaround is to follow the suggestion for the error message and add '-fno-range-check' - in that case I got no warning or error. The report originates from a flang github issue: https://github.com/flang-compiler/flang/issues/992 and was pointed out by Bryan Chan. I tried gfortran 7.5.0 and 10.2.0 and both acted the same.