Debian Codegraph @

gcc/testsuite/gfortran.dg/associate_63.f90

raw
1 ! { dg-do run }
2 !
3 ! Test the fix for PR112834 in which class array function selectors caused
4 ! problems for both ASSOCIATE and SELECT_TYPE.
5 !
6 ! Contributed by Paul Thomas <[email protected]>
7 !
8 module m
9 implicit none
10 type t
11 integer :: i = 0
12 end type t
13 integer :: i = 0
14 type(t), parameter :: test_array (2) = [t(42),t(84)], &
15 test_scalar = t(99)
16 end module m
17 module class_selectors
18 use m
19 implicit none
20 private
21 public foo2
22 contains
23 function bar3() result(res)
24 class(t), allocatable :: res(:)
25 allocate (res, source = test_array)
26 end
27
28 subroutine foo2()
29 associate (var1 => bar3())
30 if (any (var1%i .ne. test_array%i)) stop 1
31 if (var1(2)%i .ne. test_array(2)%i) stop 2
32 associate (zzz3 => var1%i)
33 if (any (zzz3 .ne. test_array%i)) stop 3
34 if (zzz3(2) .ne. test_array(2)%i) stop 4
35 end associate
36 select type (x => var1)
37 type is (t)
38 if (any (x%i .ne. test_array%i)) stop 5
39 if (x(2)%i .ne. test_array(2)%i) stop 6
40 class default
41 stop 7
42 end select
43 end associate
44
45 select type (y => bar3 ())
46 type is (t)
47 if (any (y%i .ne. test_array%i)) stop 8
48 if (y(2)%i .ne. test_array(2)%i) stop 9
49 class default
50 stop 10
51 end select
52 end subroutine foo2
53 end module class_selectors
54
55 use class_selectors
56 call foo2
57 end