Debian Codegraph @

gcc/testsuite/gfortran.dg/zero_sized_14.f90

raw
1 ! { dg-do run }
2 ! PR fortran/86277
3 !
4 ! Check proper detection of presence of optional array dummy arguments
5 ! for zero-sized actual array arguments or array constructors:
6 ! tests for REAL (as non-character intrinsic type) and empty derived type
7
8 program test
9 implicit none
10 real, parameter :: m(0) = 42.
11 real, parameter :: n(1) = 23.
12 real :: x(0) = 1.
13 real :: z(1) = 2.
14 real :: w(0)
15 real, pointer :: p(:)
16 real, allocatable :: y(:)
17 integer :: k = 0, l = 0 ! Test/failure counter
18 type dt
19 ! Empty type
20 end type dt
21 type(dt), parameter :: t0(0) = dt()
22 type(dt), parameter :: t1(1) = dt()
23 type(dt) :: t2(0) = dt()
24 type(dt) :: t3(1) = dt()
25 type(dt) :: t4(0)
26 type(dt), allocatable :: tt(:)
27 !
28 allocate (p(0))
29 allocate (y(0))
30 allocate (tt(0))
31 call a0 ()
32 call a1 ()
33 call a2 ()
34 call a3 ()
35 call all_missing ()
36 print *, "Total tests:", k, " failed:", l
37 contains
38 subroutine a0 ()
39 print *, "Variables as actual argument"
40 call i (m)
41 call i (n)
42 call i (x)
43 call i (w)
44 call i (y)
45 call i (p)
46 call j (t0)
47 call j (t1)
48 call j (t2)
49 call j (t3)
50 call j (t4)
51 call j (tt)
52 print *, "Array section as actual argument"
53 call i (m(1:0))
54 call i (n(1:0))
55 call i (x(1:0))
56 call i (w(1:0))
57 call i (z(1:0))
58 call i (p(1:0))
59 call j (t0(1:0))
60 call j (t1(1:0))
61 call j (t2(1:0))
62 call j (t3(1:0))
63 call j (t4(1:0))
64 call j (tt(1:0))
65 end subroutine a0
66 !
67 subroutine a1 ()
68 print *, "Explicit temporary as actual argument"
69 call i ((m))
70 call i ((n))
71 call i ((n(1:0)))
72 call i ((x))
73 call i ((w))
74 call i ((z(1:0)))
75 call i ((y))
76 call i ((p))
77 call i ((p(1:0)))
78 call j ((t0))
79 call j ((t1))
80 call j ((tt))
81 call j ((t1(1:0)))
82 call j ((tt(1:0)))
83 end subroutine a1
84 !
85 subroutine a2 ()
86 print *, "Array constructor as actual argument"
87 call i ([m])
88 call i ([n])
89 call i ([x])
90 call i ([w])
91 call i ([z])
92 call i ([m(1:0)])
93 call i ([n(1:0)])
94 call i ([m,n(1:0)])
95 call i ([x(1:0)])
96 call i ([w(1:0)])
97 call i ([z(1:0)])
98 call i ([y])
99 call i ([p])
100 call i ([y,y])
101 call i ([p,p])
102 call i ([y(1:0)])
103 call i ([p(1:0)])
104 call j ([t0])
105 call j ([t0,t0])
106 call j ([t1])
107 call j ([tt])
108 call j ([tt,tt])
109 call j ([t1(1:0)])
110 call j ([tt(1:0)])
111 end subroutine a2
112 !
113 subroutine a3 ()
114 print *, "Array constructor with type-spec as actual argument"
115 call i ([real:: ])
116 call i ([real:: 7])
117 call i ([real:: m])
118 call i ([real:: n])
119 call i ([real:: x])
120 call i ([real:: w])
121 call i ([real:: m(1:0)])
122 call i ([real:: n(1:0)])
123 call i ([real:: m,n(1:0)])
124 call i ([real:: x(1:0)])
125 call i ([real:: w(1:0)])
126 call i ([real:: z(1:0)])
127 call i ([real:: y])
128 call i ([real:: p])
129 call i ([real:: y,y])
130 call i ([real:: p,p])
131 call i ([real:: y(1:0)])
132 call i ([real:: p(1:0)])
133 call j ([ dt :: ])
134 call j ([ dt :: t0])
135 call j ([ dt :: t0,t0])
136 call j ([ dt :: t1])
137 call j ([ dt :: tt])
138 call j ([ dt :: tt,tt])
139 call j ([ dt :: t1(1:0)])
140 call j ([ dt :: tt(1:0)])
141 end subroutine a3
142 !
143 subroutine i (arg)
144 real, optional, intent(in) :: arg(:)
145 logical :: t
146 t = present (arg)
147 k = k + 1
148 print *, 'test', k, merge (" ok", "FAIL", t)
149 if (.not. t) l = l + 1
150 if (.not. t) stop k
151 end subroutine i
152 !
153 subroutine j (arg)
154 type(dt), optional, intent(in) :: arg(:)
155 logical :: t
156 t = present (arg)
157 k = k + 1
158 print *, 'test', k, merge (" ok", "FAIL", t)
159 if (.not. t) l = l + 1
160 if (.not. t) stop k
161 end subroutine j
162 !
163 subroutine all_missing (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
164 real, optional, intent(in) :: arg1(:)
165 real, optional, allocatable :: arg2(:)
166 real, optional, pointer :: arg3(:)
167 character(*), optional, intent(in) :: arg4(:)
168 character(*), optional, allocatable :: arg5(:)
169 character(*), optional, pointer :: arg6(:)
170 character(:), optional, pointer :: arg7(:)
171 character(:), optional, allocatable :: arg8(:)
172 if (present (arg1)) stop 101
173 if (present (arg2)) stop 102
174 if (present (arg3)) stop 103
175 if (present (arg4)) stop 104
176 if (present (arg5)) stop 105
177 if (present (arg6)) stop 106
178 if (present (arg7)) stop 107
179 if (present (arg8)) stop 108
180 end subroutine all_missing
181 end program