インテル® Fortran コンパイラー 19.0 デベロッパー・ガイドおよびリファレンス
Statement: Denotes a finalization procedure that defines one or more final subroutines that are bound to a derived type. It takes the following form:
FINAL [::] sub1 [, sub2 ]...
sub1, sub2, ... |
Is a final subroutine, which is a module procedure with exactly one dummy argument of the derived type. The dummy argument cannot be INTENT(OUT), it cannot be optional, and it cannot be a pointer or allocatable. All array shape and length type parameters are assumed. |
A final subroutine must not have a dummy argument with the same kind type parameters and rank as the dummy argument of another final subroutine of the type.
You cannot specify a subroutine that was previously specified as a final subroutine for the derived type.
This statement is used in derived-type type-bound procedures.
A derived type is finalizable only if it has a final subroutine or a nonpointer, nonallocatable component of finalizable type. A nonpointer data entity is finalizable only if it is of finalizable type.
When an entity is finalized, the following occurs:
If the dynamic type of the entity has a final subroutine whose dummy argument has the same kind type parameters and rank as the entity being finalized, it is called with the entity as an actual argument
Otherwise, if there is an elemental final subroutine whose dummy argument has the same kind type parameters as the entity being finalized, it is called with the entity as an actual argument.
Otherwise, no subroutine is called.
Effects of Finalization
If the entity being finalized is an array, each finalizable component of each element of that array is finalized separately.
When a pointer is deallocated, its target is finalized. When an allocatable entity is deallocated, it is finalized.
A nonpointer, nonallocatable object that is not a dummy argument or function result is finalized immediately before it would become undefined due to execution of a RETURN or END statement.
If the entity is of extended type and the parent type is finalizable, the parent component is finalized.
A nonpointer, nonallocatable local variable of a BLOCK construct is finalized immediately before it would become undefined due to termination of the BLOCK construct.
The following rules also apply:
If an executable construct references a function, the result is finalized after execution of the innermost executable construct containing the reference.
If an executable construct references a structure constructor or array constructor, the entity created by the constructor is finalized after execution of the innermost executable construct containing the reference.
If a specification expression in a scoping unit references a function, the result is finalized before execution of the executable constructs in the scoping unit.
If a specification expression in a scoping unit references a structure constructor or array constructor, the entity created by the constructor is finalized before execution of the executable constructs in the scoping unit.
If image execution is terminated, either by an error or by execution of a ERROR STOP, STOP, or END PROGRAM statement, any entities that exist immediately before termination are not finalized.
The following example declares two module subroutines to be final:
TYPE MY_TYPE
... ! Component declarations
CONTAINS
FINAL :: CLEAN1, CLEAN2
END TYPE MY_TYPE