Fortran · 850 bytes Raw Blame History
1 ! audit31 Finding 15: locally declared derived-type vars inside a
2 ! BLOCK never ran their FINAL subroutines because the Stmt::Block
3 ! lowering just restored the shadowed outer locals and returned.
4 ! F2018 §7.5.6.3 / §9.7.3.2 require finalization and implicit
5 ! deallocation at END BLOCK. Gather the block-introduced keys and
6 ! route them through insert_implicit_dealloc before the restore
7 ! step. Task #496.
8 ! CHECK: finalizer id= 9
9 program audit31_block_finalizer
10 implicit none
11 type :: counted_t
12 integer :: id = 0
13 contains
14 final :: destroy_counted
15 end type
16
17 print *, 'before'
18 block
19 type(counted_t) :: c
20 c%id = 9
21 print *, 'inside'
22 end block
23 print *, 'after'
24 contains
25 subroutine destroy_counted(this)
26 type(counted_t), intent(inout) :: this
27 print *, 'finalizer id=', this%id
28 end subroutine
29 end program
30