Debian Codegraph @

gcc/testsuite/gfortran.dg/finalize_42.f90

raw
1 ! { dg-do run }
2 !
3 ! Test the fix for PR71798 in which the result of 'create_mytype'
4 ! was not being finalized after the completion of the assignment
5 ! statement.
6 !
7 ! Contributed by Jonathan Hogg <[email protected]>
8 !
9 module mymod
10 implicit none
11
12 integer :: next = 0
13
14 type :: mytype
15 integer :: idx = -1
16 contains
17 procedure :: mytype_assign
18 generic :: assignment(=) => mytype_assign
19 final :: mytype_final
20 end type mytype
21
22 contains
23 subroutine mytype_assign(this, other)
24 class(mytype), intent(inout) :: this
25 class(mytype), intent(in) :: other
26
27 this%idx = next
28 next = next + 1
29 end subroutine mytype_assign
30
31 subroutine mytype_final(this)
32 type(mytype) :: this
33 next = next + 1
34 if (this%idx /= 0) stop 1 ! finalize 'create_mtype' result
35 end subroutine mytype_final
36
37 type(mytype) function create_mytype()
38 create_mytype%idx = next
39 next = next + 1
40 end function create_mytype
41
42 end module mymod
43
44 program test
45 use mymod
46 implicit none
47
48 type(mytype) :: x
49
50 x = create_mytype()
51 if (x%idx /= 1) stop 2 ! Defined assignment failed
52 if (next /= 3) stop 3 ! Used to give 2 because finalization did not occur
53 end program test