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

            Bug ID: 96319
           Summary: Don't warn for LOGICAL kind conversion with
                    -Wconversion
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jb at gcc dot gnu.org
  Target Milestone: ---

From
https://stackoverflow.com/questions/62937435/compilation-warning-with-gfortran-on-assignment-of-logicalc-bool-variable

Consider the program

PROGRAM boolean
   USE ISO_C_BINDING
   IMPLICIT NONE
   LOGICAL (KIND = C_BOOL) :: cbool
   INTEGER :: i, j
   i = 1
   j = 2
   cbool = i /= j
   WRITE(*,*) cbool
END PROGRAM boolean

Compiling with

gfortran boolean.f90 -o boolean -Wall

results in the warning

boolean.f90:8:11:

    8 |    cbool = i /= j
      |           1
Warning: Possible change of value in conversion from LOGICAL(4) to LOGICAL(1)
at (1) [-Wconversion]


The warning is incorrect here as there's only one value bit in the LOGICAL
variable regardless of the kind, and thus there is no risk of losing data even
if this is a narrowing conversion.

Reply via email to