https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107362
federico <federico.perini at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |federico.perini at gmail dot com --- Comment #2 from federico <federico.perini at gmail dot com> --- I'm getting the same issue on a recursive tree structure, I will post my testcase here instead of opening a new bug. I see a segfault in the default finalizer (I think it gets called when a recursive type is returned as a function result). I get the segfault on the default finalization routine with all gfortran versions, 7.1 to 12.1. This is also potentially linked to bug 106606 (in this case, the class is not polymorphic). Test program (also see on godbolt at: https://godbolt.org/z/PxYGhM8j9) module t type :: tree type(tree), allocatable :: node end type tree type :: container type(tree) :: root end type container contains type(container) function do_something() result(c) allocate(c%root%node) allocate(c%root%node%node) allocate(c%root%node%node%node) end function do_something end module t program test_function_output use t call create_and_finalize() contains subroutine create_and_finalize() type(container) :: c1,c2 c1 = do_something() c2 = c1 print *, 'allocated? 0 ',allocated(c1%root%node) print *, 'allocated? 1 ',allocated(c1%root%node%node) print *, 'allocated? 2 ',allocated(c1%root%node%node%node) end subroutine create_and_finalize end program test_function_output Thanks, Federico