1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
3 ! When a module subprogram has the MODULE prefix the following must match
4 ! with the corresponding separate module procedure interface body:
5 ! - C1549: characteristics and dummy argument names
6 ! - C1550: binding label
7 ! - C1551: NON_RECURSIVE prefix
11 module subroutine s4(x
)
14 module subroutine s5(x
, y
)
18 module subroutine s6(x
, y
)
22 module subroutine s7(x
, y
, z
)
27 module subroutine s8(x
, y
, z
)
32 module subroutine s9(x
, y
, z
, w
)
38 module subroutine s10(x
, y
, z
, w
)
39 real x(0:), y(:), z(0:*), w(*)
46 module subroutine s4(x
)
47 !ERROR: The intent of dummy argument 'x' does not match the intent of the corresponding argument in the interface body
48 real, intent(out
) :: x
50 module subroutine s5(x
, y
)
51 !ERROR: Dummy argument 'x' has the OPTIONAL attribute; the corresponding argument in the interface body does not
52 real, pointer, optional
:: x
53 !ERROR: Dummy argument 'y' does not have the VALUE attribute; the corresponding argument in the interface body does
56 module subroutine s6(x
, y
)
57 !ERROR: Dummy argument 'x' has type INTEGER(4); the corresponding argument in the interface body has distinct type REAL(4)
59 !ERROR: Dummy argument 'y' has type REAL(8); the corresponding argument in the interface body has distinct type REAL(4)
62 module subroutine s7(x
, y
, z
)
63 integer, parameter :: n
= 8
66 !ERROR: The shape of dummy argument 'z' does not match the shape of the corresponding argument in the interface body
69 module subroutine s8(x
, y
, z
)
70 !ERROR: The shape of dummy argument 'x' does not match the shape of the corresponding argument in the interface body
73 !ERROR: The shape of dummy argument 'z' does not match the shape of the corresponding argument in the interface body
76 module subroutine s9(x
, y
, z
, w
)
78 !ERROR: Dummy argument 'y' has type CHARACTER(KIND=1,LEN=5_8); the corresponding argument in the interface body has distinct type CHARACTER(KIND=1,LEN=4_8)
81 !ERROR: Dummy argument 'w' has type CHARACTER(KIND=1,LEN=4_8); the corresponding argument in the interface body has distinct type CHARACTER(KIND=1,LEN=*)
84 module subroutine s10(x
, y
, z
, w
)
85 real x(:), y(0:), z(*), w(0:*) ! all ok, lower bounds don't matter
91 module subroutine s1(x
, y
)
93 real, intent(out
) :: y
95 module subroutine s2(x
, y
)
97 real, intent(out
) :: y
99 module subroutine s3(x
, y
)
103 module subroutine s4()
105 non_recursive
module subroutine s5()
112 !ERROR: Module subprogram 's1' has 3 args but the corresponding interface body has 2
113 module subroutine s1(x
, y
, z
)
114 real, intent(in
) :: x
115 real, intent(out
) :: y
118 module subroutine s2(x
, z
)
119 real, intent(in
) :: x
120 !ERROR: Dummy argument name 'z' does not match corresponding name 'y' in interface body
121 real, intent(out
) :: z
123 module subroutine s3(x
, y
)
124 !ERROR: Dummy argument 'x' is a procedure; the corresponding argument in the interface body is not
126 !ERROR: Dummy argument 'y' is a data object; the corresponding argument in the interface body is not
129 !ERROR: Module subprogram 's4' has NON_RECURSIVE prefix but the corresponding interface body does not
130 non_recursive
module subroutine s4()
132 !ERROR: Module subprogram 's5' does not have NON_RECURSIVE prefix but the corresponding interface body does
133 module subroutine s5()
139 module subroutine s1()
141 module subroutine s2() bind(c
, name
="s2")
143 module subroutine s3() bind(c
, name
="s3")
145 module subroutine s4() bind(c
, name
=" s4")
147 module subroutine s5() bind(c
)
149 module subroutine s6() bind(c
)
151 module subroutine s7() bind(c
, name
="s7")
157 character(*), parameter :: suffix
= "_xxx"
159 !ERROR: Module subprogram 's1' has a binding label but the corresponding interface body does not
160 !ERROR: Module subprogram 's1' and its corresponding interface body are not both BIND(C)
161 module subroutine s1() bind(c
, name
="s1")
163 !ERROR: Module subprogram 's2' does not have a binding label but the corresponding interface body does
164 !ERROR: Module subprogram 's2' and its corresponding interface body are not both BIND(C)
165 module subroutine s2()
167 !ERROR: Module subprogram 's3' has binding label 's3_xxx' but the corresponding interface body has 's3'
168 module subroutine s3() bind(c
, name
="s3" // suffix
)
170 module subroutine s4() bind(c
, name
="s4 ")
172 module subroutine s5() bind(c
, name
=" s5")
174 !ERROR: Module subprogram 's6' has binding label 'not_s6' but the corresponding interface body has 's6'
175 module subroutine s6() bind(c
, name
="not_s6")
184 module subroutine s1(x
, y
, z
)
185 procedure(real), pointer, intent(in
) :: x
186 procedure(real), pointer, intent(out
) :: y
187 procedure(real), pointer, intent(out
) :: z
189 module subroutine s2(x
, y
)
190 procedure(real), pointer :: x
198 module subroutine s1(x
, y
, z
)
199 procedure(real), pointer, intent(in
) :: x
200 !ERROR: The intent of dummy argument 'y' does not match the intent of the corresponding argument in the interface body
201 procedure(real), pointer, intent(inout
) :: y
202 !ERROR: The intent of dummy argument 'z' does not match the intent of the corresponding argument in the interface body
203 procedure(real), pointer :: z
205 module subroutine s2(x
, y
)
206 !ERROR: Dummy argument 'x' has the OPTIONAL attribute; the corresponding argument in the interface body does not
207 !ERROR: Dummy argument 'x' does not have the POINTER attribute; the corresponding argument in the interface body does
208 procedure(real), optional
:: x
209 !ERROR: Dummy argument 'y' has the POINTER attribute; the corresponding argument in the interface body does not
210 procedure(real), pointer :: y
219 subroutine s_real2(x
)
222 subroutine s_integer(x
)
225 module subroutine s1(x
)
226 procedure(s_real
) :: x
228 module subroutine s2(x
)
229 procedure(s_real
) :: x
236 module subroutine s1(x
)
238 procedure(s_real2
) :: x
240 module subroutine s2(x
)
241 !ERROR: Dummy procedure 'x' is not compatible with the corresponding argument in the interface body: incompatible dummy procedure interfaces: incompatible dummy argument #1: incompatible dummy data object types: INTEGER(4) vs REAL(4)
242 procedure(s_integer
) :: x
251 module subroutine s2()
258 !ERROR: Module subroutine 'f1' was declared as a function in the corresponding interface body
259 module subroutine f1()
261 !ERROR: Module function 's2' was declared as a subroutine in the corresponding interface body
283 real module function f1()
285 !ERROR: Result of function 'f2' is not compatible with the result of the corresponding interface body: function results have distinct types: INTEGER(4) vs REAL(4)
286 integer module function f2()
288 !ERROR: Result of function 'f3' is not compatible with the result of the corresponding interface body: function results have incompatible attributes
297 module subroutine s1(x
, *)
305 !ERROR: Dummy argument 1 of 's1' is an alternate return indicator but the corresponding argument in the interface body is not
306 !ERROR: Dummy argument 2 of 's1' is not an alternate return indicator but the corresponding argument in the interface body is
307 module subroutine s1(*, x
)
314 pure elemental
module subroutine s1
321 !Ensure no spurious error about mismatching attributes
328 module subroutine sub1(s
)
331 module subroutine sub2(s
)
339 module subroutine sub1(s
)
340 character(len
=-1) s
! ok
342 module subroutine sub2(s
)
343 !ERROR: Dummy argument 's' has type CHARACTER(KIND=1,LEN=1_8); the corresponding argument in the interface body has distinct type CHARACTER(KIND=1,LEN=0_8)
350 module character(2) function f()
356 !ERROR: Result of function 'f' is not compatible with the result of the corresponding interface body: function results have distinct types: CHARACTER(KIND=1,LEN=3_8) vs CHARACTER(KIND=1,LEN=2_8)
357 module character(3) function f()
363 module subroutine s(x
)
364 ! The subroutine/function distinction is not known.
371 !WARNING: Dummy procedure 'x' does not exactly match the corresponding argument in the interface body
372 module subroutine s(x
)