https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67472
Bug ID: 67472 Summary: Finalizer not invoked for undefined and unreferenced local variable Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: ian_harvey at bigpond dot com Target Milestone: --- gfortran recent trunk r227512 does not invoke the finalizer for the local variable `aa` of the internal procedure `internal`. module test_final_mod implicit none type :: my_final integer :: n = 0 contains final :: destroy_scalar end type my_final contains subroutine destroy_scalar(self) type(my_final), intent(inout) :: self print "(A,I0,A,*(I0,:,', '))", & 'destroy_scalar executed for object with component value ', & self%n end subroutine destroy_scalar end module test_final_mod program test_internal_proc use test_final_mod call internal contains subroutine internal type(my_final) :: aa end subroutine internal end program test_internal_proc gfortran produces no output, the expected output is: destroy_scalar executed for object with component value 0 The expected output is generated if the source is changed, such that the local variable is defined or referenced in the internal procedure.