https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65792
Paul Thomas <pault at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pault at gcc dot gnu.org --- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> --- Created attachment 35400 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35400&action=edit Draft Patch The attached patch bootstraps and regtests with Andre's patch for .. and pr65841 remains fixed. Have extended Mikael's test case to include a function call to verify that there are no memory leaks. ! { dg-do run } ! ! PR fortran/65792 ! The evaluation of the argument in the call to new_prt_spec2 ! failed to properly initialize the comp component. ! While the array contents were properly copied, the array bounds remained ! uninitialized. ! ! Contributed by Dominique D'Humieres <domi...@lps.ens.fr> program main implicit none integer, parameter :: n = 2 type :: string_t character(LEN=1), dimension(:), allocatable :: chars end type string_t type :: string_container_t type(string_t) :: comp end type string_container_t type(string_t) :: prt_in, tmp, tmpa(n) type(string_container_t) :: tmpc, tmpca(n) integer :: i, j, k do i=1,16 ! scalar elemental function with structure constructor prt_in = string_t(["D"]) tmpc = new_prt_spec2 (string_container_t(prt_in)) print *, tmpc%comp%chars deallocate (prt_in%chars) deallocate(tmpc%comp%chars) tmpc = new_prt_spec2 (string_container_t(new_str_t(["h","e","l","l","o"]))) print *, tmpc%comp%chars deallocate(tmpc%comp%chars) end do contains impure elemental function new_prt_spec2 (name) result (prt_spec) type(string_container_t), intent(in) :: name type(string_container_t) :: prt_spec prt_spec = name end function new_prt_spec2 function new_str_t (name) result (prt_spec) character (*), intent(in), dimension (:) :: name type(string_t) :: prt_spec prt_spec = string_t(name) end function new_str_t end program main I will submit tomorrow evening. Paul