'MEM[(struct m *)&s + 56B]' may be used uninitialized in this function

Andrew Benson abenson@carnegiescience.edu
Thu Jun 14 08:06:00 GMT 2018


With gfortran 8.0.1 the following code (reduced from a much larger code, so 
there are obvious things wrong with it):

module mtc
  type :: t
     integer, allocatable, dimension(:) :: a
  end type t
  type :: m
     type(t), allocatable, dimension(:) :: fs
  end type m
contains
  subroutine ap(s,ps)
    class(m), intent(inout) :: s
    type(t), dimension(:), allocatable, intent(inout) :: ps
    ps(:)=[t([0]),t([0])]
  end subroutine ap
  function rcp() result(s)
    type(m) :: s
    type(t), allocatable, dimension(:) :: fs
    type(t), dimension(:), allocatable :: aps
    allocate(fs(2))
    s=m(fs)
    call ap(s,aps)
  end function rcp
end module mtc

gives the following when compiled:

$ gfortran -c 059.F90 -O1 -Wall 
059.F90:9:17:

   subroutine ap(s,ps)
                 1
Warning: Unused dummy argument 's' at (1) [-Wunused-dummy-argument]
059.F90:19:0:

     s=m(fs)
 
Warning: 'MEM[(struct m *)&s + 48B]' may be used uninitialized in this 
function [-Wmaybe-uninitialized]
059.F90:19:0: Warning: 'MEM[(struct m *)&s + 56B]' may be used uninitialized 
in this function [-Wmaybe-uninitialized]
059.F90:19:0: Warning: 'fs.span' may be used uninitialized in this function [-
Wmaybe-uninitialized]

I can probably figure out what's causing the "may be used uninitialized" in 
this reduced case, but I wondered if the:

'MEM[(struct m *)&s + 48B]' 

is as intended, or if this should be the name of some member variable in type 
"m" instead?

(The first warning, about the unused dummy argument, is easily fixed of course, 
but if I remove the dummy argument the maybe-uninitialized warning goes away.)

-Andrew



More information about the Fortran mailing list