Type constructor and final behavior

Apparently not. An answer can be found in the thread Automatic finalization of derived types. Quoting the answer there:

7.5.6.4 Entities that are not finalized

If image execution is terminated, either by an error (e.g. an allocation failure) or by execution of a stop-stmt, error-stop-stmt, or end-program-stmt, entities existing immediately prior to termination are not finalized.

NOTE 1
A nonpointer, nonallocatable object that has the SAVE attribute is never finalized as a direct consequence of the execution of a RETURN or END statement.

According to thread I just mentioned, your options are to wrap the contents of the main program in a block or a subroutine.

This has to do with intrinsic assignment of polymorphic entities. See Finalization/Copy in intrinsic polymorphic assignment. I’ve only skimmed that thread, but according to my understanding, the banana on the left-hand side is finalized before assignment, after assignment, the leaky_t temporary object is also finalized. No finalization is performed at the end due to point 7.5.6.4.

1 Like