3 ! Test the fix for all three variants of PR82996, which used to
4 ! segfault in the original testcase and ICE in the testcases of
7 ! Contributed by Neil Carlson <neil.n.carlson@gmail.com>
10 integer :: final_count_foo
= 0
11 integer :: final_count_bar
= 0
14 ! This is the original testcase, with a final routine 'foo' but
15 ! but not in the container type 'bar1'.
19 private foo
, foo_destroy
21 integer, pointer :: f(:) => null()
29 impure elemental
subroutine foo_destroy(this
)
30 type(foo
), intent(inout
) :: this
31 final_count_foo
= final_count_foo
+ 1
32 if (associated(this
%f
)) deallocate(this
%f
)
36 ! Comment 1 was the same as original, except that the
37 ! 'foo' finalizer is elemental and a 'bar' finalizer is added..
41 private foo
, foo_destroy
, bar_destroy
43 integer, pointer :: f(:) => null()
53 impure elemental
subroutine foo_destroy(this
)
54 type(foo
), intent(inout
) :: this
55 final_count_foo
= final_count_foo
+ 1
56 if (associated(this
%f
)) deallocate(this
%f
)
58 subroutine bar_destroy(this
)
59 type(bar2
), intent(inout
) :: this
60 final_count_bar
= final_count_bar
+ 1
61 call foo_destroy(this
%b
)
65 ! Comment 2 was the same as comment 1, except that the 'foo'
66 ! finalizer is no longer elemental.
70 private foo
, foo_destroy
, bar_destroy
72 integer, pointer :: f(:) => null()
82 subroutine foo_destroy(this
)
83 type(foo
), intent(inout
) :: this
84 final_count_foo
= final_count_foo
+ 1
85 if (associated(this
%f
)) deallocate(this
%f
)
87 subroutine bar_destroy(this
)
88 type(bar3
), intent(inout
) :: this
89 final_count_bar
= final_count_bar
+ 1
90 do j
= 1, size(this
%b
)
91 call foo_destroy(this
%b(j
))
105 if (final_count_foo
/= 2) stop 1
106 if (final_count_bar
/= 0) stop 2
108 if (final_count_foo
/= 6) stop 3
109 if (final_count_bar
/= 1) stop 4
111 if (final_count_foo
/= 8) stop 5
112 if (final_count_bar
/= 2) stop 6
115 type(bar1
), intent(out
) :: x
118 type(bar2
), intent(out
) :: x
121 type(bar3
), intent(out
) :: x