3 ! Test assumed rank finalizers
6 ! F2018: 7.5.6.2 para 1: "Otherwise, if there is an elemental final
7 ! subroutine whose dummy argument has the same kind type parameters
8 ! as the entity being finalized, or a final subroutine whose dummy
9 ! argument is assumed-rank with the same kind type parameters as the
10 ! entity being finalized, it is called with the entity as an actual
20 interface finalizable_type
21 module procedure construct0
, construct1
24 integer :: final_ctr
= 0
28 pure
function construct0(component
) result(finalizable
)
29 integer, intent(in
) :: component
30 type(finalizable_t
) finalizable
31 finalizable
%component_
= component
34 impure
function construct1(component
) result(finalizable
)
35 integer, intent(in
), dimension(:) :: component
36 type(finalizable_t
), dimension(:), allocatable
:: finalizable
39 allocate (finalizable (sz
))
40 finalizable
%component_
= component
43 subroutine finalize(self
)
44 type(finalizable_t
), intent(inout
), dimension (..) :: self
47 print *, "rank 0 value = ", self
%component_
49 print *, "rank 1 value = ", self
%component_
51 print *, "rank default"
53 final_ctr
= final_ctr
+ 1
58 program specification_expression_finalization
62 type(finalizable_t
) :: a
= finalizable_t (1)
63 type(finalizable_t
) :: b(2) = [finalizable_t (2), finalizable_t (3)]
65 a
= finalizable_type (42)
66 if (final_ctr
.ne
. 2) stop 1
67 b
= finalizable_type ([42, 43])