1! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
2! Test 15.5.2.9(2,3,5) dummy procedure requirements
3
4module m
5 contains
6
7  integer function intfunc(x)
8    integer, intent(in) :: x
9    intfunc = x
10  end function
11  real function realfunc(x)
12    real, intent(in) :: x
13    realfunc = x
14  end function
15
16  subroutine s01(p)
17    procedure(realfunc), pointer, intent(in) :: p
18  end subroutine
19  subroutine s02(p)
20    procedure(realfunc), pointer :: p
21  end subroutine
22
23  subroutine selemental1(p)
24    procedure(cos) :: p ! ok
25  end subroutine
26
27  real elemental function elemfunc(x)
28    real, intent(in) :: x
29    elemfunc = x
30  end function
31  subroutine selemental2(p)
32    !ERROR: A dummy procedure may not be ELEMENTAL
33    procedure(elemfunc) :: p
34  end subroutine
35
36  function procptr()
37    procedure(realfunc), pointer :: procptr
38    procptr => realfunc
39  end function
40  function intprocptr()
41    procedure(intfunc), pointer :: intprocptr
42    intprocptr => intfunc
43  end function
44
45  subroutine test1 ! 15.5.2.9(5)
46    procedure(realfunc), pointer :: p
47    procedure(intfunc), pointer :: ip
48    p => realfunc
49    ip => intfunc
50    call s01(realfunc) ! ok
51    !ERROR: Actual argument procedure has interface incompatible with dummy argument 'p='
52    call s01(intfunc)
53    call s01(p) ! ok
54    call s01(procptr()) ! ok
55    !ERROR: Actual argument procedure has interface incompatible with dummy argument 'p='
56    call s01(intprocptr())
57    call s01(null()) ! ok
58    call s01(null(p)) ! ok
59    !ERROR: Actual argument procedure has interface incompatible with dummy argument 'p='
60    call s01(null(ip))
61    call s01(sin) ! ok
62    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a POINTER unless INTENT(IN)
63    call s02(realfunc)
64    call s02(p) ! ok
65    !ERROR: Actual argument procedure has interface incompatible with dummy argument 'p='
66    call s02(ip)
67    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a POINTER unless INTENT(IN)
68    call s02(procptr())
69    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a POINTER unless INTENT(IN)
70    call s02(null())
71    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a POINTER unless INTENT(IN)
72    call s02(null(p))
73    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a POINTER unless INTENT(IN)
74    call s02(sin)
75  end subroutine
76
77  subroutine callsub(s)
78    call s
79  end subroutine
80  subroutine takesrealfunc1(f)
81    external f
82    real f
83  end subroutine
84  subroutine takesrealfunc2(f)
85    x = f(1)
86  end subroutine
87  subroutine forwardproc(p)
88    implicit none
89    external :: p ! function or subroutine not known
90    call foo(p)
91  end subroutine
92
93  subroutine test2(unknown,ds,drf,dif) ! 15.5.2.9(2,3)
94    external :: unknown, ds, drf, dif
95    real :: drf
96    integer :: dif
97    procedure(callsub), pointer :: ps
98    procedure(realfunc), pointer :: prf
99    procedure(intfunc), pointer :: pif
100    call ds ! now we know that's it's a subroutine
101    call callsub(callsub) ! ok apart from infinite recursion
102    call callsub(unknown) ! ok
103    call callsub(ds) ! ok
104    call callsub(ps) ! ok
105    call takesrealfunc1(realfunc) ! ok
106    call takesrealfunc1(unknown) ! ok
107    call takesrealfunc1(drf) ! ok
108    call takesrealfunc1(prf) ! ok
109    call takesrealfunc2(realfunc) ! ok
110    call takesrealfunc2(unknown) ! ok
111    call takesrealfunc2(drf) ! ok
112    call takesrealfunc2(prf) ! ok
113    call forwardproc(callsub) ! ok
114    call forwardproc(realfunc) ! ok
115    call forwardproc(intfunc) ! ok
116    call forwardproc(unknown) ! ok
117    call forwardproc(ds) ! ok
118    call forwardproc(drf) ! ok
119    call forwardproc(dif) ! ok
120    call forwardproc(ps) ! ok
121    call forwardproc(prf) ! ok
122    call forwardproc(pif) ! ok
123    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
124    call callsub(realfunc)
125    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
126    call callsub(intfunc)
127    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
128    call callsub(drf)
129    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
130    call callsub(dif)
131    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
132    call callsub(prf)
133    !ERROR: Actual argument associated with procedure dummy argument 's=' is a function but must be a subroutine
134    call callsub(pif)
135    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
136    call takesrealfunc1(callsub)
137    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
138    call takesrealfunc1(ds)
139    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
140    call takesrealfunc1(ps)
141    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
142    call takesrealfunc1(intfunc)
143    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
144    call takesrealfunc1(dif)
145    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
146    call takesrealfunc1(pif)
147    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
148    call takesrealfunc1(intfunc)
149    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
150    call takesrealfunc2(callsub)
151    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
152    call takesrealfunc2(ds)
153    !ERROR: Actual argument associated with procedure dummy argument 'f=' is a subroutine but must be a function
154    call takesrealfunc2(ps)
155    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
156    call takesrealfunc2(intfunc)
157    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
158    call takesrealfunc2(dif)
159    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
160    call takesrealfunc2(pif)
161    !ERROR: Actual argument function associated with procedure dummy argument 'f=' has incompatible result type
162    call takesrealfunc2(intfunc)
163  end subroutine
164end module
165