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

Gerhard Steinmetz <gerhard.steinmetz.fort...@t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gerhard.steinmetz.fortran@t
                   |                            |-online.de

--- Comment #2 from Gerhard Steinmetz <gerhard.steinmetz.fort...@t-online.de> 
---
Replacing "size" with synonym "product(shape)" unveils an uninitialized value.


$ cat z2.f90
program p
  implicit none
  character(len=:), allocatable :: string
  integer, dimension(4), target :: array = [1,2,3,4]
  integer, dimension(:), pointer :: array_ptr
  integer :: ptr_size
  array_ptr => array
  ptr_size = size(array_ptr)

  print *, size(array_ptr)
  print *, product(shape(array_ptr))

  allocate (character(len=product(shape(array_ptr))) :: string)

  print *, len(string)
end


$ gfortran-6 -g -O0 -Wall -fcheck=all -ftrapv z2.f90
z2.f90:13:0:

   allocate (character(len=product(shape(array_ptr))) :: string)

Warning: 'val.7' may be used uninitialized in this function
[-Wmaybe-uninitialized]
z2.f90:13:0: Warning: '.string' may be used uninitialized in this function
[-Wmaybe-uninitialized]


$ a.out
           4
           4
   682229200

$ a.out
           4
           4
  1947807840

$ a.out
           4
           4
 -1207271008

Reply via email to