| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! PR fortran/37336 |
| 4 |
! |
| 5 |
! Test for finalization of nonallocatable variables |
| 6 |
! |
| 7 |
module m |
| 8 |
implicit none |
| 9 |
type t |
| 10 |
integer :: i |
| 11 |
contains |
| 12 |
final :: finit |
| 13 |
end type t |
| 14 |
integer, save :: called_final = -1 |
| 15 |
contains |
| 16 |
impure elemental subroutine finit(x) |
| 17 |
type(t), intent(in) :: x |
| 18 |
if (called_final == -1) STOP 1 |
| 19 |
called_final = called_final + 1 |
| 20 |
if (called_final /= x%i) STOP 2 |
| 21 |
end subroutine finit |
| 22 |
end module m |
| 23 |
|
| 24 |
use m |
| 25 |
implicit none |
| 26 |
type(t) :: x2, y2(2) |
| 27 |
block |
| 28 |
type(t) :: xx, yy(2) |
| 29 |
type(t), save :: x3, y3(2) |
| 30 |
yy%i = [1, 2] |
| 31 |
xx%i = 3 |
| 32 |
y3%i = [-4, -5] |
| 33 |
x3%i = -6 |
| 34 |
called_final = 0 |
| 35 |
end block |
| 36 |
if (called_final /= 3) STOP 1 |
| 37 |
called_final = -1 |
| 38 |
y2%i = [-7, -8] |
| 39 |
x2%i = -9 |
| 40 |
end |