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

            Bug ID: 81962
           Summary: -Wmaybe-uninitialized refers to wrong line (and only
                    works with -O3)
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org
  Target Milestone: ---

Consider this Fortran test case:


module ce

implicit none

contains

   subroutine ce3(a)
      real, intent(in) :: a
      if (a <= 0.) then
         print *,"error"
      end if
   end subroutine

   subroutine cee(Y)
      real, intent(in) :: Y
      real :: alpha
      if (Y>0.) then
         alpha = Y
      else
         print *,"error"
      end if
      call ce3(alpha)
   end subroutine

end module



Compiling with "gfortran-7 -Wall -O3", I get:

ce.f90:9:0:

       if (a <= 0.) then

Warning: ‘alpha’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
ce.f90:16:0:

       real :: alpha

note: ‘alpha’ was declared here


The fact that one gets a warning here is good in principle, but there are two
problems:

1) The line that is referred to is not really the right one. In particular it
does not contain any mention of 'alpha', which can be really confusing for
larger codes.  The warning should instead refer to the line "call ce3(alpha)".

2) The warning disappears when -O3 is not used (or with a lower warning level).

Reply via email to