рассмотрите следующую небольшую программу, которая воспроизводит ошибку сегментации, которую я получаю с gfortran gcc 9.2.0 для mac os):
module stringmod
type :: str_t
character(len=:), allocatable :: s
contains
final :: finalize
end type str_t
type :: static_t
type(str_t) :: expr(3)
end type static_t
type :: dynamic_t
type(str_t), allocatable :: expr(:)
end type dynamic_t
contains
subroutine finalize ( x )
type(str_t), intent(in out) :: x
if (allocated(x%s)) deallocate(x%s)
end subroutine finalize
end module stringmod
use stringmod
implicit none
type(static_t ), allocatable :: stat(:)
type(dynamic_t), allocatable :: dyna(:)
integer :: i, j, n = 10
allocate(stat(n),dyna(n))
do i = 1, n
allocate(dyna(i)%expr(3))
end do
! No problem when deallocating "dyna":
deallocate(dyna)
! while deallocating "stat"causes a segfault with gfortran (gcc 9.2.0 for mac os)
! (unless the final method is removed from the DT):
deallocate(stat)
end
Segfault возникает только при освобождении массива типа static_t, который имеет явный член массива типа str_t. Странно, вроде связано с финальным методом DT str_t (когда убираю эту процедуру проблема уходит), но причины не вижу.