| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! PR fortran/92178 |
| 4 |
! Re-order argument deallocation |
| 5 |
|
| 6 |
program p |
| 7 |
implicit none |
| 8 |
integer, allocatable :: a(:) |
| 9 |
class(*), allocatable :: c(:) |
| 10 |
type t |
| 11 |
integer, allocatable :: a(:) |
| 12 |
end type t |
| 13 |
type(t) :: b |
| 14 |
integer :: k = -999 |
| 15 |
|
| 16 |
! Test based on original PR |
| 17 |
a = [1] |
| 18 |
call assign (a, (max(a(1),0))) |
| 19 |
if (allocated (a)) stop 9 |
| 20 |
if (k /= 1) stop 10 |
| 21 |
|
| 22 |
! Additional variations based on suggestions by Tobias Burnus |
| 23 |
! to check that argument expressions are evaluated early enough |
| 24 |
a = [1, 2] |
| 25 |
call foo (allocated (a), size (a), test (a), a, allocated (a)) |
| 26 |
if (allocated (a)) stop 11 |
| 27 |
|
| 28 |
a = [1, 2] |
| 29 |
k = 1 |
| 30 |
call foo (allocated (a), size (a), test (k*a), a, allocated (a)) |
| 31 |
if (allocated (a)) stop 12 |
| 32 |
|
| 33 |
b% a = [1, 2] |
| 34 |
call foo (allocated (b% a), size (b% a), test (b% a), b% a, allocated (b% a)) |
| 35 |
if (allocated (b% a)) stop 13 |
| 36 |
|
| 37 |
c = [3, 4] |
| 38 |
call bar (allocated (c), size (c), test2 (c), c, & |
| 39 |
allocated (c), size (c), test2 (c) ) |
| 40 |
if (allocated (c)) stop 14 |
| 41 |
|
| 42 |
contains |
| 43 |
|
| 44 |
subroutine assign (a, i) |
| 45 |
integer, allocatable, intent(out) :: a(:) |
| 46 |
integer, value :: i |
| 47 |
k = i |
| 48 |
end subroutine |
| 49 |
|
| 50 |
subroutine foo (alloc, sz, tst, x, alloc2) |
| 51 |
logical, value :: alloc, tst |
| 52 |
integer, value :: sz |
| 53 |
logical :: alloc2 |
| 54 |
integer, allocatable, intent(out) :: x(:) |
| 55 |
if (allocated (x)) stop 1 |
| 56 |
if (.not. alloc) stop 2 |
| 57 |
if (sz /= 2) stop 3 |
| 58 |
if (.not. tst) stop 4 |
| 59 |
if (.not. alloc2) stop 15 |
| 60 |
end subroutine foo |
| 61 |
! |
| 62 |
logical function test (zz) |
| 63 |
integer :: zz(2) |
| 64 |
test = zz(2) == 2 |
| 65 |
end function test |
| 66 |
! |
| 67 |
subroutine bar (alloc, sz, tst, x, alloc2, sz2, tst2) |
| 68 |
logical, value :: alloc, tst, alloc2, tst2 |
| 69 |
integer, value :: sz, sz2 |
| 70 |
class(*), allocatable, intent(out) :: x(:) |
| 71 |
if (allocated (x)) stop 5 |
| 72 |
if (.not. alloc) stop 6 |
| 73 |
if (sz /= 2) stop 7 |
| 74 |
if (.not. tst) stop 8 |
| 75 |
if (.not. alloc2) stop 16 |
| 76 |
if (sz2 /= 2) stop 17 |
| 77 |
if (.not. tst2) stop 18 |
| 78 |
end subroutine bar |
| 79 |
! |
| 80 |
logical function test2 (zz) |
| 81 |
class(*), intent(in) :: zz(:) |
| 82 |
select type (zz) |
| 83 |
type is (integer) |
| 84 |
test2 = zz(2) == 4 |
| 85 |
class default |
| 86 |
stop 99 |
| 87 |
end select |
| 88 |
end function test2 |
| 89 |
end |