In case it's useful to gfortran developers, the Reference-Counter repository (https://github.com/sourceryinstitute/reference-counter) contains a test/compiler_test.f90 file that separately tests each of the scenarios in which Fortran 2018 clause 7.5.6.3 requires type finalization to occur. Thanks to the contributions of Wileam Phan and Brad Richardson, one function tests each scenario. A comment near the top of each such function cites the paragraph number of the corresponding requirement. To download and run the tests on macOS or Linux with gfortran 12.1.0 and the Fortran Package Manager (fpm) already installed, execute the following commands:
git clone https://github.com/sourceryinstitute/reference-counter cd reference-counter fpm test for which the trailing output is Running Tests Test that The compiler finalizes a non-allocatable object on the LHS of an intrinsic assignment finalizes an allocated allocatable LHS of an intrinsic assignment finalizes a target when the associated pointer is deallocated finalizes an object upon explicit deallocation finalizes a non-pointer non-allocatable array object at the END statement finalizes a non-pointer non-allocatable object at the end of a block construct finalizes a function reference on the RHS of an intrinsic assignment finalizes a specification expression function result finalizes an intent(out) derived type dummy argument finalizes an allocatable component object A ref_reference does not leak when constructed, assigned, and then explicitly freed A total of 11 test cases Failed Took 1.94e-4 seconds Test that The compiler finalizes a non-allocatable object on the LHS of an intrinsic assignment Expected |1| but got |0| finalizes an allocated allocatable LHS of an intrinsic assignment Expected |1| but got |0| finalizes a function reference on the RHS of an intrinsic assignment Expected |1| but got |0| finalizes a specification expression function result Expected |1| but got |0| 4 of 11 cases failed 4 of 11 assertions failed STOP 1 <ERROR> Execution failed for object " reference-counter-test " <ERROR>*cmd_run*:stopping due to failed executions STOP 1