Debian Codegraph @

gcc/testsuite/gfortran.dg/optional_absent_10.f90

raw
1 ! { dg-do run }
2 ! PR fortran/113377
3 !
4 ! Test passing of missing optional arguments of intrinsic type
5 ! to scalar dummies of elemental subroutines
6
7 module m_char
8 implicit none
9 contains
10 subroutine test_char ()
11 character :: k(7) = "#"
12 character(4) :: c(7) = "*"
13 call one (k)
14 call one_val (k)
15 call one_ij (k)
16 call one_jj (k)
17 call one_j4 (k)
18 call three (c)
19 call three_val (c)
20 call three_ij (c)
21 call three_jj (c)
22 call three_j4 (c)
23 end subroutine test_char
24
25 subroutine one (i, j)
26 character, intent(in) :: i(7)
27 character, intent(in), optional :: j
28 character, allocatable :: aa
29 character, pointer :: pp => NULL()
30 if (present (j)) stop 1
31 call two (i, j)
32 call two_val (i, j)
33 call two (i, aa)
34 call two (i, pp)
35 call two_val (i, aa)
36 call two_val (i, pp)
37 end
38
39 subroutine one_val (i, j)
40 character, intent(in) :: i(7)
41 character, value, optional :: j
42 if (present (j)) stop 2
43 call two (i, j)
44 call two_val (i, j)
45 end
46
47 subroutine one_ij (i, j)
48 character, intent(in) :: i(7)
49 character, intent(in), optional :: j(7)
50 if (present (j)) stop 3
51 call two (i, j)
52 call two_val (i, j)
53 end
54
55 subroutine one_jj (i, j)
56 character, intent(in) :: i(7)
57 character, intent(in), optional :: j(:)
58 if (present (j)) stop 4
59 call two (i, j)
60 call two_val (i, j)
61 end
62
63 subroutine one_j4 (i, j)
64 character, intent(in) :: i(:)
65 character, intent(in), optional :: j(7)
66 if (present (j)) stop 5
67 call two (i, j)
68 call two_val (i, j)
69 end
70
71 elemental subroutine two (i, j)
72 character, intent(in) :: i
73 character, intent(in), optional :: j
74 if (present (j)) error stop 11
75 end
76
77 elemental subroutine two_val (i, j)
78 character, intent(in) :: i
79 character, value, optional :: j
80 if (present (j)) error stop 12
81 end
82
83 subroutine three (i, j)
84 character(4), intent(in) :: i(7)
85 character(4), intent(in), optional :: j
86 character(4), allocatable :: aa
87 character(4), pointer :: pp => NULL()
88 if (present (j)) stop 6
89 call four (i, j)
90 call four_val (i, j)
91 call four (i, aa)
92 call four (i, pp)
93 call four_val (i, aa)
94 call four_val (i, pp)
95 end
96
97 subroutine three_val (i, j)
98 character(4), intent(in) :: i(7)
99 character(4), value, optional :: j
100 if (present (j)) stop 7
101 call four (i, j)
102 call four_val (i, j)
103 end
104
105 subroutine three_ij (i, j)
106 character(4), intent(in) :: i(7)
107 character(4), intent(in), optional :: j(7)
108 if (present (j)) stop 8
109 call four (i, j)
110 call four_val (i, j)
111 end
112
113 subroutine three_jj (i, j)
114 character(4), intent(in) :: i(7)
115 character(4), intent(in), optional :: j(:)
116 if (present (j)) stop 9
117 call four (i, j)
118 call four_val (i, j)
119 end
120
121 subroutine three_j4 (i, j)
122 character(4), intent(in) :: i(:)
123 character(4), intent(in), optional :: j(7)
124 if (present (j)) stop 10
125 call four (i, j)
126 call four_val (i, j)
127 end
128
129 elemental subroutine four (i, j)
130 character(4), intent(in) :: i
131 character(4), intent(in), optional :: j
132 if (present (j)) error stop 13
133 end
134
135 elemental subroutine four_val (i, j)
136 character(4), intent(in) :: i
137 character(4), value, optional :: j
138 if (present (j)) error stop 14
139 end
140 end
141
142 module m_int
143 implicit none
144 contains
145 subroutine test_int ()
146 integer :: k(4) = 1
147 call one (k)
148 call one_val (k)
149 call one_ij (k)
150 call one_jj (k)
151 call one_j4 (k)
152 end
153
154 subroutine one (i, j)
155 integer, intent(in) :: i(4)
156 integer, intent(in), optional :: j
157 integer, allocatable :: aa
158 integer, pointer :: pp => NULL()
159 if (present (j)) stop 21
160 call two (i, j)
161 call two_val (i, j)
162 call two (i, aa)
163 call two (i, pp)
164 call two_val (i, aa)
165 call two_val (i, pp)
166 end
167
168 subroutine one_val (i, j)
169 integer, intent(in) :: i(4)
170 integer, value, optional :: j
171 if (present (j)) stop 22
172 call two (i, j)
173 call two_val (i, j)
174 end
175
176 subroutine one_ij (i, j)
177 integer, intent(in) :: i(4)
178 integer, intent(in), optional :: j(4)
179 if (present (j)) stop 23
180 call two (i, j)
181 call two_val (i, j)
182 end
183
184 subroutine one_jj (i, j)
185 integer, intent(in) :: i(4)
186 integer, intent(in), optional :: j(:)
187 if (present (j)) stop 24
188 call two (i, j)
189 call two_val (i, j)
190 end
191
192 subroutine one_j4 (i, j)
193 integer, intent(in) :: i(:)
194 integer, intent(in), optional :: j(4)
195 if (present (j)) stop 25
196 call two (i, j)
197 call two_val (i, j)
198 end
199
200 elemental subroutine two (i, j)
201 integer, intent(in) :: i
202 integer, intent(in), optional :: j
203 if (present (j)) error stop 31
204 end
205
206 elemental subroutine two_val (i, j)
207 integer, intent(in) :: i
208 integer, value, optional :: j
209 if (present (j)) error stop 32
210 end
211 end
212
213 program p
214 use m_int
215 use m_char
216 implicit none
217 call test_int ()
218 call test_char ()
219 end