From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD8A93857C50; Thu, 25 Mar 2021 07:40:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD8A93857C50 From: "nickpapior at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99761] New: Warn flag for non-kind specified mixing Date: Thu, 25 Mar 2021 07:40:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: fortran-dev X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nickpapior at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Thu, 25 Mar 2021 07:40:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99761 Bug ID: 99761 Summary: Warn flag for non-kind specified mixing Product: gcc Version: fortran-dev Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nickpapior at gmail dot com Target Milestone: --- Some context here: https://github.com/j3-fortran/fortran_proposals/issues/201 The basic message is that users may forget to add kind specifications for constants which are assigned to higher precision values which then loses the extra bits. Simplest example: real(8), parameter :: pi =3D 3.14159265358979323846 which actually only stores the floating point value and store that in a dou= ble precision variable, thereby loosing precision. My proposal would be to add a flag which warns about misused kinds: program test real(8), parameter :: const =3D 1.4435435345345 real(8), parameter :: const2 =3D 1./3. real(8), parameter :: const3 =3D 1._4/4._4 print *, 1./3. * const end program test it would be nice if the above could be compiled with gfortran -Wpedantic-ki= nd and something like this would be issued: 2 | real(8), parameter :: const =3D 1.4435435345345 1 Warning: Constant expression at (1) is in lower precision than variable. 3 | real(8), parameter :: const2 =3D 1./3. 1 Warning: Constant expression at (1) is in lower precision than variable. 3 | real(8), parameter :: const2 =3D 1./3. 1 Warning: Constant expression at (1) is in lower precision than variable. 5 | print *, 1./3. * const 1 2 Warning: Constant at (1) has lower precision than variable at (2) Line 4 is silently ignored due to explicit kind specification. I think such an enhancement would be extremely useful to hunt down mis-typed kind specifiers.=