| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-std=f202y -Wsurprising" } |
| 3 |
! |
| 4 |
! Test Reinhold Bader's F202y proposal "Generic processing of assumed rank objects". |
| 5 |
! Tests class assumed rank objects. |
| 6 |
! |
| 7 |
! Contributed by Paul Thomas <[email protected]> |
| 8 |
! |
| 9 |
type :: t1 |
| 10 |
integer :: i |
| 11 |
end type |
| 12 |
type, extends(t1) :: t2 |
| 13 |
integer :: j |
| 14 |
end type |
| 15 |
|
| 16 |
class(t1), allocatable :: x(:,:) |
| 17 |
type(t2), parameter :: xp(*) = [t2(t1(1),2),t2(t1(3),4),t2(t1(5),6),t2(t1(7),8)] |
| 18 |
x = reshape (xp, [2,2]) |
| 19 |
call my_sub1 (x) |
| 20 |
if (any (x(2:1:-1,2:1:-1)%i .ne. reshape (xp%i, [2,2]))) stop 1 |
| 21 |
call my_sub2 (x) |
| 22 |
if (any (x(2:1:-1,2:1:-1)%i .ne. reshape (xp%i, [2,2]))) stop 2 |
| 23 |
deallocate (x) |
| 24 |
contains |
| 25 |
subroutine my_sub1 (class_arg) |
| 26 |
class(t1), contiguous, target :: class_arg(..) |
| 27 |
class(t1), pointer :: cp(:) |
| 28 |
integer :: cp_sz |
| 29 |
integer :: lb(1) |
| 30 |
integer :: ub(1) |
| 31 |
integer :: slb = 2 |
| 32 |
|
| 33 |
cp_sz = size (class_arg) |
| 34 |
cp(slb:slb+cp_sz-1) => class_arg |
| 35 |
if (any (cp%i .ne. xp%i)) stop 3 |
| 36 |
if (size (cp) .ne. cp_sz) stop 4 |
| 37 |
if (ubound (cp, 1) .ne. slb+cp_sz-1) stop 5 |
| 38 |
|
| 39 |
associate (ca(slb:slb+cp_sz-1) => class_arg) |
| 40 |
lb = lbound (ca) |
| 41 |
ub = ubound (ca) |
| 42 |
if (size (ca) .ne. cp_sz) stop 6 |
| 43 |
if (ubound (ca, 1) .ne. slb+cp_sz-1) stop 7 |
| 44 |
select type (ca) |
| 45 |
type is (t2) |
| 46 |
ca = ca(ub(1):lb(1):-1) |
| 47 |
class default |
| 48 |
end select |
| 49 |
end associate |
| 50 |
end |
| 51 |
|
| 52 |
subroutine my_sub2 (class_arg) |
| 53 |
class(*), contiguous, target :: class_arg(..) |
| 54 |
class(*), pointer :: cp(:, :) |
| 55 |
integer :: cp_sz |
| 56 |
cp_sz = size (class_arg) |
| 57 |
cp(1:cp_sz/2, 1:cp_sz/2) => class_arg |
| 58 |
call check (cp, cp_sz) |
| 59 |
associate (ca(2:3,1:2) => class_arg) |
| 60 |
select type (ca) |
| 61 |
type is (t2) |
| 62 |
ca = ca(3:2:-1,2:1:-1) |
| 63 |
class default |
| 64 |
end select |
| 65 |
end associate |
| 66 |
end |
| 67 |
|
| 68 |
subroutine check (arg, sz) |
| 69 |
class(*), intent(inOUT) :: arg(:, :) |
| 70 |
integer :: sz |
| 71 |
integer :: lb(2) |
| 72 |
integer :: ub(2) |
| 73 |
lb = lbound(arg) |
| 74 |
ub = ubound(arg) |
| 75 |
select type (s => arg) |
| 76 |
type is (t2) |
| 77 |
s = s(ub(1):lb(1):-1,ub(2):lb(1):-1) |
| 78 |
if (any (reshape (s(lb(1):ub(1),lb(2):ub(2))%j, [sz]) & |
| 79 |
.ne. xp%j)) stop 8 |
| 80 |
|
| 81 |
class default |
| 82 |
stop 9 |
| 83 |
end select |
| 84 |
end |
| 85 |
end |