public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99561] New: gfortran reports an error for a truncation that is permitted by the standard
@ 2021-03-12 13:33 michal.paszta at mobica dot com
  2021-03-12 18:39 ` [Bug fortran/99561] " kargl at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: michal.paszta at mobica dot com @ 2021-03-12 13:33 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2021-03-12 19:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 13:33 [Bug fortran/99561] New: gfortran reports an error for a truncation that is permitted by the standard michal.paszta at mobica dot com
2021-03-12 18:39 ` [Bug fortran/99561] " kargl at gcc dot gnu.org
2021-03-12 18:51 ` kargl at gcc dot gnu.org
2021-03-12 19:20 ` sgk at troutmask dot apl.washington.edu

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