Allocatable components are not being finalized when their parent object is deallocated?
MODULE m IMPLICIT NONE TYPE :: Thing CONTAINS FINAL :: thing_Final END TYPE Thing TYPE, PUBLIC :: Parent TYPE(Thing), ALLOCATABLE :: a_thing CONTAINS FINAL :: parent_Final END TYPE Parent CONTAINS SUBROUTINE thing_Final(obj) TYPE(Thing), INTENT(INOUT) :: obj PRINT *, 'Component final' END SUBROUTINE thing_Final SUBROUTINE parent_Final(obj) TYPE(Parent), INTENT(INOUT) :: obj PRINT *, 'Parent final' END SUBROUTINE parent_Final END MODULE m PROGRAM final_test USE m IMPLICIT NONE TYPE(Parent), ALLOCATABLE :: a ALLOCATE(a) ALLOCATE(a%a_thing) DEALLOCATE(a) END PROGRAM final_test
[U:projectsFortranMiscFortranMisc] >ifort /check:all /warn:all /standard-semantics "2013-01-29 final.f90" && "2013-01-29 final.exe" Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 220.127.116.11 Build 20121008 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. 2013-01-29 final.f90(20): remark #7712: This variable has not been used. [OBJ] SUBROUTINE parent_Final(obj) --------------------------^ 2013-01-29 final.f90(15): remark #7712: This variable has not been used. [OBJ] SUBROUTINE thing_Final(obj) -------------------------^ Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. "-out:2013-01-29 final.exe" -subsystem:console "2013-01-29 final.obj" Parent final
In the above the parent object is finalizable, but I think even if it wasn't (no final:: parent_Final statement) the finalizer for a%a_thing should still be called. Mentioned previously in http://software.intel.com/en-us/forums/topic/278463 and http://software.intel.com/en-us/forums/topic/284434 and possibly in other threads, so perhaps this is all well known, but I couldn't find a definitive issue id.