| 1 |
! { dg-do run } |
| 2 |
! Test fix for PR105168, in which nterface mapping was failing with CLASS 'x' |
| 3 |
! and parentheses around the actual argument. |
| 4 |
! |
| 5 |
! Contributed by Gerhard Steinmetz <[email protected]> |
| 6 |
! |
| 7 |
module m |
| 8 |
type t |
| 9 |
integer :: a |
| 10 |
contains |
| 11 |
final :: final_t |
| 12 |
end type |
| 13 |
integer :: cntr = 0 |
| 14 |
contains |
| 15 |
function f(x, factor) result(z) |
| 16 |
class(t) :: x(:) ! Worked, with or without parentheses if s/CLASS/TYPE/ |
| 17 |
type(t) :: z(2) |
| 18 |
integer :: factor |
| 19 |
z = x ! Seg fault here |
| 20 |
z%a = factor * z%a |
| 21 |
end |
| 22 |
impure elemental subroutine final_t (arg) |
| 23 |
type (t), intent(in) :: arg |
| 24 |
cntr = cntr + 1 |
| 25 |
end subroutine |
| 26 |
end module |
| 27 |
program p |
| 28 |
use m |
| 29 |
class(t), allocatable :: y(:), z(:) |
| 30 |
y = [t(2),t(4)] |
| 31 |
allocate (t :: z(2)) |
| 32 |
z = f((y), 1) ! Failed even with parentheses removed |
| 33 |
if (any(z%a /= [2,4])) stop 1 |
| 34 |
z = f(y, 2) ! Failed but now OK |
| 35 |
if (any (z%a /= [4,8])) stop 2 |
| 36 |
deallocate (y, z) |
| 37 |
if (cntr /= 16) stop 3 ! 6 for each assignment and 4 for deallocation |
| 38 |
end |