Pure procedure and intent(out) polymorphic pointer argument

I just checked J3/24-007, 7.5.6.3,

7.5.6.3 When finalization occurs

[…]

When a pointer is deallocated its target is finalized. When an allocatable entity is deallocated, it is finalizedunless it is the variable in an intrinsic assignment statement. If an error condition occurs during deallocation, it is processor dependent whether finalization occurs

[…]

When a procedure is invoked, a nonpointer, nonallocatable, INTENT (OUT) dummy argument of that procedure is finalized before it becomes undefined. The finalization caused by INTENT (OUT) is considered to occur within the invoked procedure; so for elemental procedures, an INTENT (OUT) argument will be finalized only if a scalar or elemental final subroutine is available, regardless of the rank of the actual argument.

If an object is allocated via pointer allocation and later becomes unreachable due to all pointers associated with that object having their pointer association status changed, it is processor dependent whether it is finalized. If it is finalized, it is processor dependent as to when the final subroutines are called.

According to the last paragraph, the pointer intent(out) case can potentially trigger finalization of a derived type.

1 Like