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

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 62545
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62545&action=edit
Fix for this PR

This runs without memory leaks:

module input_output_pair_m
  implicit none

  type input_output_pair_t(k)
    integer, kind :: k
    integer :: a, b
  end type

  type mini_batch_t(k)
    integer, kind :: k = kind(1.)
    type(input_output_pair_t(k)), allocatable :: input_output_pairs_(:)
  end type

  interface

    module function default_real_construct()
      implicit none
      type(mini_batch_t) default_real_construct
    end function

  end interface

end module

submodule(input_output_pair_m) input_output_pair_smod
contains
  function default_real_construct()
   type(mini_batch_t) default_real_construct
   allocate (default_real_construct%input_output_pairs_(2))
   default_real_construct%input_output_pairs_%a = 42
   default_real_construct%input_output_pairs_%b = 420
  end
end submodule

  use input_output_pair_m
  type(mini_batch_t), allocatable :: res
  res = default_real_construct()
  print *, res%input_output_pairs_%a
  print *, res%input_output_pairs_%a
  print *, storage_size (res%input_output_pairs_)
  if (allocated (res)) deallocate (res)
end

Reply via email to