Fortran · 936 bytes Raw Blame History
1 ! audit31 harvest: FINAL procedure declared in a module, used on a
2 ! local derived-type variable inside a BLOCK in the program.
3 ! Sprint 31 #496 made the BLOCK-scope finalization fire; this test
4 ! checks that the finalizer is found through a cross-module use-
5 ! association rather than only in-program scope, and runs at END
6 ! BLOCK with the component value intact.
7 ! CHECK: inside block
8 ! CHECK: finalizer ran for id= 7
9 ! CHECK: after block
10 module audit31_final_mod
11 implicit none
12 type :: counted_t
13 integer :: id = 0
14 contains
15 final :: destroy_counted
16 end type
17 contains
18 subroutine destroy_counted(this)
19 type(counted_t), intent(inout) :: this
20 print *, 'finalizer ran for id=', this%id
21 end subroutine
22 end module
23
24 program audit31_final_cross_module
25 use audit31_final_mod
26 implicit none
27 block
28 type(counted_t) :: c
29 c%id = 7
30 print *, 'inside block'
31 end block
32 print *, 'after block'
33 end program
34