public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99761] New: Warn flag for non-kind specified mixing
@ 2021-03-25  7:40 nickpapior at gmail dot com
  2021-03-25 10:31 ` [Bug fortran/99761] " dominiq at lps dot ens.fr
  2021-03-25 10:41 ` nickpapior at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: nickpapior at gmail dot com @ 2021-03-25  7:40 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/99761] Warn flag for non-kind specified mixing
  2021-03-25  7:40 [Bug fortran/99761] New: Warn flag for non-kind specified mixing nickpapior at gmail dot com
@ 2021-03-25 10:31 ` dominiq at lps dot ens.fr
  2021-03-25 10:41 ` nickpapior at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-03-25 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Try -Wconversion-extra.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/99761] Warn flag for non-kind specified mixing
  2021-03-25  7:40 [Bug fortran/99761] New: Warn flag for non-kind specified mixing nickpapior at gmail dot com
  2021-03-25 10:31 ` [Bug fortran/99761] " dominiq at lps dot ens.fr
@ 2021-03-25 10:41 ` nickpapior at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: nickpapior at gmail dot com @ 2021-03-25 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Nick <nickpapior at gmail dot com> ---
Amazing, years of using gfortran and you still find useful flags!

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-25 10:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25  7:40 [Bug fortran/99761] New: Warn flag for non-kind specified mixing nickpapior at gmail dot com
2021-03-25 10:31 ` [Bug fortran/99761] " dominiq at lps dot ens.fr
2021-03-25 10:41 ` nickpapior at gmail dot com

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).