From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6D8B8386F41E; Fri, 12 Mar 2021 18:39:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D8B8386F41E From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99561] gfortran reports an error for a truncation that is permitted by the standard Date: Fri, 12 Mar 2021 18:39:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: resolution bug_status cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 18:39:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99561 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: >=20 > INTEGER(KIND=3D1) :: var8 =3D 257_2 >=20 > 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 Standa= rd. >=20 The sentence preceding Table 10.9 and the table tell you=20 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=3D1) 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=20 two's complement wrap-around semantics. You do not get truncation, where I assume you mean that an out-of-range=20 value is truncated to -128 or 127 as the situation would merit (e.g., var8 =3D 257_2 <-- huge(var8) =3D 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 =3D 257_2 | 1 Warning: Conversion from 'INTEGER(2)' to 'INTEGER(1)' at (1) [-Wconversion]=