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

            Bug ID: 96047
           Summary: Bogus unitialized warning for derived type with
                    allocatable components
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jellby at yahoo dot com
  Target Milestone: ---

The program below gives a bogus warning when compiling with -O0, but not with
-O1 or higher:

$ gfortran a.f90 -Wall -O0
a.f90:9:0:

 call new(a,3)

Warning: ‘a.dim[0].ubound’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
a.f90:9:0: Warning: ‘a.dim[0].lbound’ may be used uninitialized in this
function [-Wmaybe-uninitialized]

The warning goes away if the "allocate(a(0))" line is uncommented, but that
should not be necessary, because the argument is "intent(out)", so it it must
be allocated in the subroutine.

$ cat a.f90
program test
implicit none
type foo
  real, allocatable :: c(:)
end type foo
type(foo), allocatable :: a(:)

!allocate(a(0))
call new(a,3)

contains

subroutine new(m,n)
type(foo), allocatable, intent(out) :: m(:)
integer, intent(in) :: n
integer :: i
allocate(m(n))
do i=1,n
  allocate(m(i)%c(n))
end do
end subroutine new

end program

Reply via email to