c: Fix up pointer types to may_alias structures [PR114493]
[official-gcc.git] / gcc / testsuite / gfortran.dg / class_array_20.f03
blob8a718bab32e7672f47ed381f899351a18b4d24d1
1 ! { dg-do run }
3 ! Test contributed by Thomas L. Clune via pr60322
4 !                  and Antony Lewis via pr64692
6 program class_array_20
7   implicit none
9   type Foo
10   end type
12   type(foo), dimension(2:3) :: arg
13   integer :: oneDarr(2)
14   integer :: twoDarr(2,3)
15   integer :: x, y
16   double precision :: P(2, 2)
18   ! Checking for PR/60322
19   call copyFromClassArray([Foo(), Foo()])
20   call copyFromClassArray(arg)
21   call copyFromClassArray(arg(:))
23   x= 3
24   y= 4
25   oneDarr = [x, y]
26   call W([x, y])
27   call W(oneDarr)
28   call W([3, 4])
30   twoDarr = reshape([3, 4, 5, 5, 6, 7], [2, 3])
31   call WtwoD(twoDarr)
32   call WtwoD(reshape([3, 4, 5, 5, 6, 7], [2, 3]))
34   ! Checking for PR/64692
35   P(1:2, 1) = [1.d0, 2.d0]
36   P(1:2, 2) = [3.d0, 4.d0]
37   call AddArray(P(1:2, 2))
39 contains
41   subroutine copyFromClassArray(classarray)
42     class (Foo), intent(in) :: classarray(:)
44     if (lbound(classarray, 1) .ne. 1) STOP 1
45     if (ubound(classarray, 1) .ne. 2) STOP 2
46     if (size(classarray) .ne. 2) STOP 3
47   end subroutine
49   subroutine AddArray(P)
50     class(*), target, intent(in) :: P(:)
51     class(*), pointer :: Pt(:)
53     allocate(Pt(1:size(P)), source= P)
55     select type (P)
56       type is (double precision)
57         if (abs(P(1)-3.d0) .gt. 1.d-8) STOP 4
58         if (abs(P(2)-4.d0) .gt. 1.d-8) STOP 5
59       class default
60         STOP 6
61     end select
63     select type (Pt)
64       type is (double precision)
65         if (abs(Pt(1)-3.d0) .gt. 1.d-8) STOP 7
66         if (abs(Pt(2)-4.d0) .gt. 1.d-8) STOP 8
67       class default
68         STOP 9
69     end select
70   end subroutine
72   subroutine W(ar)
73     class(*), intent(in) :: ar(:)
75     if (lbound(ar, 1) /= 1) STOP 10
76     select type (ar)
77       type is (integer)
78         ! The indeces 1:2 are essential here, or else one would not
79         ! note, that the array internally starts at 0, although the
80         ! check for the lbound above went fine.
81         if (any (ar(1:2) .ne. [3, 4])) STOP 11
82       class default
83         STOP 12
84     end select
85   end subroutine
87   subroutine WtwoD(ar)
88     class(*), intent(in) :: ar(:,:)
90     if (any (lbound(ar) /= [1, 1])) STOP 13
91     select type (ar)
92       type is (integer)
93         if (any (reshape(ar(1:2,1:3), [6]) .ne. [3, 4, 5, 5, 6, 7])) &
94         STOP 14
95       class default
96         STOP 15
97     end select
98   end subroutine
99 end program class_array_20