Debian Codegraph @

gcc/testsuite/gfortran.dg/class_74.f90

raw
1 ! { dg-do compile }
2 ! { dg-additional-options "-fcoarray=single" }
3 !
4 ! PR fortran/106856
5 !
6 ! Contributed by G. Steinmetz
7 !
8 subroutine foo
9 interface
10 subroutine bar(x)
11 type(*) :: x
12 end subroutine bar
13 end interface
14 class(*) :: x, y
15 allocatable :: x
16 dimension :: x(:), y(:,:)
17 codimension :: x[:]
18 pointer :: y
19 y => null()
20 if (allocated(x)) then
21 call bar(x(2)[1])
22 end if
23 if (associated(y)) then
24 call bar(y(2,2))
25 end if
26 end subroutine foo
27
28
29 program p
30 class(*), allocatable :: x, y
31 y = 'abc'
32 call s1(x, y)
33 contains
34 subroutine s1(x, y)
35 class(*) :: x, y
36 end
37 subroutine s2(x, y)
38 class(*), allocatable :: x, y
39 optional :: x
40 end
41 end
42
43
44 subroutine s1 (x)
45 class(*) :: x
46 allocatable :: x
47 dimension :: x(:)
48 if (allocated (x)) print *, size (x)
49 end
50
51 subroutine s2 (x)
52 class(*) :: x
53 allocatable :: x(:)
54 if (allocated (x)) print *, size (x)
55 end
56
57 subroutine s3 (x)
58 class(*) :: x(:)
59 allocatable :: x
60 if (allocated (x)) print *, size (x)
61 end
62
63 subroutine s4 (x)
64 class(*) :: x
65 dimension :: x(:)
66 allocatable :: x
67 if (allocated (x)) print *, size (x)
68 end
69
70
71 subroutine c0 (x)
72 class(*) :: x
73 allocatable :: x
74 codimension :: x[:]
75 dimension :: x(:)
76 if (allocated (x)) print *, size (x)
77 end
78
79 subroutine c1 (x)
80 class(*) :: x(:)
81 allocatable :: x[:]
82 if (allocated (x)) print *, size (x)
83 end
84
85 subroutine c2 (x)
86 class(*) :: x[:]
87 allocatable :: x(:)
88 if (allocated (x)) print *, size (x)
89 end
90
91 subroutine c3 (x)
92 class(*) :: x(:)[:]
93 allocatable :: x
94 if (allocated (x)) print *, size (x)
95 end
96
97 subroutine c4 (x)
98 class(*) :: x
99 dimension :: x(:)
100 codimension :: x[:]
101 allocatable :: x
102 if (allocated (x)) print *, size (x)
103 end
104
105
106 subroutine p1 (x)
107 class(*) :: x
108 pointer :: x
109 dimension :: x(:)
110 if (associated (x)) print *, size (x)
111 end
112
113 subroutine p2 (x)
114 class(*) :: x
115 pointer :: x(:)
116 if (associated (x)) print *, size (x)
117 end
118
119 subroutine p3 (x)
120 class(*) :: x(:)
121 pointer :: x
122 if (associated (x)) print *, size (x)
123 end
124
125 subroutine p4 (x)
126 class(*) :: x
127 dimension :: x(:)
128 pointer :: x
129 if (associated (x)) print *, size (x)
130 end
131
132
133 ! Testcase by Mikael Morin
134 subroutine mm ()
135 pointer :: y
136 dimension :: y(:,:)
137 class(*) :: y
138 if (associated (y)) print *, size (y)
139 end
140
141 ! Testcase from pr53951
142 subroutine pr53951 ()
143 type t
144 end type t
145 class(t), pointer :: C
146 TARGET :: A
147 class(t), allocatable :: A, B
148 TARGET :: B
149 C => A ! Valid
150 C => B ! Valid, but was rejected
151 end