There seems to be a bug in ifort Version 188.8.131.52 regarding the finalization of allocated variables of extended type.
I don't think it has been reported in the forum.
Consider the following code:
MODULE modu TYPE :: a_t CONTAINS FINAL :: d_a END TYPE a_t TYPE, EXTENDS (a_t) :: b_t CONTAINS FINAL :: d_b END TYPE b_t CONTAINS SUBROUTINE d_a(this) TYPE (a_t) :: this PRINT *, "finalize a" END SUBROUTINE d_a SUBROUTINE d_b(this) TYPE (b_t) :: this PRINT *, "finalize b" END SUBROUTINE d_b END MODULE modu PROGRAM test USE modu PRINT *, " sub1 " CALL sub1() PRINT *, " sub2 " CALL sub2() PRINT *, " sub3 " CALL sub3() CONTAINS SUBROUTINE sub1() TYPE (b_t) :: c END SUBROUTINE sub1 SUBROUTINE sub2() CLASS (a_t), ALLOCATABLE :: c ALLOCATE(b_t :: c) END SUBROUTINE sub2 SUBROUTINE sub3() CLASS (a_t), ALLOCATABLE :: c ALLOCATE(b_t :: c) DEALLOCATE(c) PRINT *, "deallocated" END SUBROUTINE sub3 END PROGRAM test
The finalization process for the variables in each of the subroutines sub1, sub2, sub3 is different (although it shouldn't be):
The variable in sub1 is finalized correctly (the final routine for the extended type is called, which, in turn, calls the final routine of the base type).
The variable in sub2 is finalized by calling the final routine of the base type (the declared type) only.
The variable in sub3 is finalized when deallocated explicitly by calling twice (!) the final routine of the base type. It is finalized again (although it shouldn't) at the end of the subroutine, by calling once the final routine of the base type.