Intel® Fortran Compiler 17.0 Developer Guide and Reference

FINAL Statement

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.

Description

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:

  1. 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

  2. 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.

  3. 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:

Example

The following example declares two module subroutines to be final:


TYPE MY_TYPE
...   ! Component declarations
CONTAINS
  FINAL :: CLEAN1, CLEAN2
END TYPE MY_TYPE

See Also