https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576
Bug ID: 106576 Summary: Finalization of temporaries from functions not occuring Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- Test case: $ cat g2.f90 module y implicit none type foo integer :: n contains final :: cleanup end type foo interface assignment (=) module procedure assign end interface assignment (=) contains subroutine assign (rop, op) type(foo), intent(inout) :: rop type(foo), intent(in) :: op rop%n = op%n + 1 print '(A12,I3)',"assign", rop%n end subroutine assign function to_foo(n) result(res) integer, intent(in) :: n type (foo) :: res res%n = n print '(A12,I3)', "to_foo", res%n end function to_foo subroutine cleanup (self) type (foo), intent(inout) :: self print '(A12,I3)', "cleanup", self%n end subroutine cleanup end module y program memain use y implicit none call chk contains subroutine chk type (foo) :: a a = to_foo(3) end subroutine chk end program memain $ gfortran g2.f90 && ./a.out to_foo 3 assign 4 cleanup 4 $ nagfor g2.f90 && ./a.out NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101 [NAG Fortran Compiler normal termination] to_foo 3 assign 4 cleanup 3 cleanup 4 NAG is in fact correct, the temporary from the function results should also be finalized. This actually blocks my little FMPFR library, so I might have a stab at this myself.