Wrong output using allocate with source= in a module subroutine
harperjf opened this issue · comments
harperjf commented
This program gives different wrong output each time it runs, but no error message, unlike my bug report #3819 where the subroutine was internal. It is now in a module. Evidence:
(lf2) john:~/Test/Glist$ cat allocinmodule.f90
! allocinmodule.f90
module test_m ! allocate with source=- is a F2008 feature
implicit none
contains
subroutine test( n )
integer, intent(in) :: n
integer, allocatable :: arr(:)
allocate( arr( 2 ), source= n )
print *, arr
!! No explicit deallocation here.
end
end module
program allocinmodule
use test_m
call test( n= 100 )
call test( n= 200 )
end program allocinmodule
(lf2) john:~/Test/Glist$ lfortran allocinmodule.f90
0 0
1536891703 5
(lf2) john:~/Test/Glist$ lfortran allocinmodule.f90
0 0
1680326320 5
(lf2) john:~/Test/Glist$
harperjf commented
Same problem if array arr was deallocated immediately after printing it.