lto: Remove random_seed from section name.
[official-gcc.git] / gcc / testsuite / gfortran.dg / finalize_42.f90
blob09178af85b6bee24aa84bd6cfa070929700adf49
1 ! { dg-do run }
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.
7 ! Contributed by Jonathan Hogg <jhogg41@gmail.com>
9 module mymod
10 implicit none
12 integer :: next = 0
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
22 contains
23 subroutine mytype_assign(this, other)
24 class(mytype), intent(inout) :: this
25 class(mytype), intent(in) :: other
27 this%idx = next
28 next = next + 1
29 end subroutine mytype_assign
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
37 type(mytype) function create_mytype()
38 create_mytype%idx = next
39 next = next + 1
40 end function create_mytype
42 end module mymod
44 program test
45 use mymod
46 implicit none
48 type(mytype) :: x
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