public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "nickpapior at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-99761-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99761

            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 = 3.14159265358979323846

which actually only stores the floating point value and store that in a double
precision variable, thereby loosing precision.

My proposal would be to add a flag which warns about misused kinds:

program test
  real(8), parameter :: const = 1.4435435345345
  real(8), parameter :: const2 = 1./3.
  real(8), parameter :: const3 = 1._4/4._4
  print *, 1./3. * const
end program test

it would be nice if the above could be compiled with gfortran -Wpedantic-kind
and something like this would be issued:


    2 |    real(8), parameter :: const = 1.4435435345345
                                         1
Warning: Constant expression at (1) is in lower precision than variable.

    3 |    real(8), parameter :: const2 = 1./3.
                                          1
Warning: Constant expression at (1) is in lower precision than variable.

    3 |    real(8), parameter :: const2 = 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.

             reply	other threads:[~2021-03-25  7:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25  7:40 nickpapior at gmail dot com [this message]
2021-03-25 10:31 ` [Bug fortran/99761] " dominiq at lps dot ens.fr
2021-03-25 10:41 ` nickpapior at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99761-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).