1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Pointer assignment constraints 10.2.2.2 (see also assign02.f90)
11 procedure(s
), pointer, nopass
:: p
17 type(t
), allocatable
:: a(:)
18 type(t
), allocatable
:: b
[:]
20 !ERROR: Procedure pointer may not be a coindexed object
27 !ERROR: In assignment to object pointer 'q', the target 's' is a procedure designator
33 a
%p
=> f() ! OK: pointer-valued function
34 !ERROR: Subroutine pointer 'p' may not be associated with function designator 'f'
38 procedure(s
), pointer :: f
43 ! C1030 and 10.2.2.4 - procedure names as target of procedure pointer
44 subroutine s4(s_dummy
)
45 procedure(s
) :: s_dummy
46 procedure(s
), pointer :: p
, q
47 procedure(), pointer :: r
49 external :: s_external
56 subroutine s_internal(i
)
60 subroutine s_module(i
)
66 procedure(f_impure1
), pointer :: p_impure
67 procedure(f_pure1
), pointer :: p_pure
68 !ERROR: Procedure pointer 'p_elemental' may not be ELEMENTAL
69 procedure(f_elemental1
), pointer :: p_elemental
70 procedure(s_impure1
), pointer :: sp_impure
71 procedure(s_pure1
), pointer :: sp_pure
72 !ERROR: Procedure pointer 'sp_elemental' may not be ELEMENTAL
73 procedure(s_elemental1
), pointer :: sp_elemental
75 p_impure
=> f_impure1
! OK, same characteristics
76 p_impure
=> f_pure1
! OK, target may be pure when pointer is not
77 p_impure
=> f_elemental1
! OK, target may be pure elemental
78 p_impure
=> f_ImpureElemental1
! OK, target may be elemental
80 sp_impure
=> s_impure1
! OK, same characteristics
81 sp_impure
=> s_pure1
! OK, target may be pure when pointer is not
82 sp_impure
=> s_elemental1
! OK, target may be elemental when pointer is not
84 !ERROR: PURE procedure pointer 'p_pure' may not be associated with non-PURE procedure designator 'f_impure1'
86 p_pure
=> f_pure1
! OK, same characteristics
87 p_pure
=> f_elemental1
! OK, target may be pure
88 !ERROR: PURE procedure pointer 'p_pure' may not be associated with non-PURE procedure designator 'f_impureelemental1'
89 p_pure
=> f_impureElemental1
91 !ERROR: PURE procedure pointer 'sp_pure' may not be associated with non-PURE procedure designator 's_impure1'
93 sp_pure
=> s_pure1
! OK, same characteristics
94 sp_pure
=> s_elemental1
! OK, target may be elemental when pointer is not
96 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_impure2'
98 !ERROR: Procedure pointer 'p_pure' associated with incompatible procedure designator 'f_pure2'
100 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_elemental2'
101 p_impure
=> f_elemental2
103 !ERROR: Procedure pointer 'sp_impure' associated with incompatible procedure designator 's_impure2'
104 sp_impure
=> s_impure2
105 !ERROR: Procedure pointer 'sp_impure' associated with incompatible procedure designator 's_pure2'
107 !ERROR: Procedure pointer 'sp_pure' associated with incompatible procedure designator 's_elemental2'
108 sp_pure
=> s_elemental2
110 !ERROR: Function pointer 'p_impure' may not be associated with subroutine designator 's_impure1'
111 p_impure
=> s_impure1
113 !ERROR: Subroutine pointer 'sp_impure' may not be associated with function designator 'f_impure1'
114 sp_impure
=> f_impure1
117 integer function f_impure1(n
)
118 real, intent(in
) :: n
121 pure
integer function f_pure1(n
)
122 real, intent(in
) :: n
125 elemental
integer function f_elemental1(n
)
126 real, intent(in
) :: n
129 impure elemental
integer function f_impureElemental1(n
)
130 real, intent(in
) :: n
131 f_impureElemental
= n
134 integer function f_impure2(n
)
135 real, intent(inout
) :: n
138 pure
real function f_pure2(n
)
139 real, intent(in
) :: n
142 elemental
integer function f_elemental2(n
)
147 subroutine s_impure1(n
)
148 integer, intent(inout
) :: n
151 pure
subroutine s_pure1(n
)
152 integer, intent(inout
) :: n
155 elemental
subroutine s_elemental1(n
)
156 integer, intent(inout
) :: n
160 subroutine s_impure2(n
) bind(c
)
161 integer, intent(inout
) :: n
163 end subroutine s_impure2
164 pure
subroutine s_pure2(n
)
165 integer, intent(out
) :: n
167 end subroutine s_pure2
168 elemental
subroutine s_elemental2(m
,n
)
169 integer, intent(inout
) :: m
, n
171 end subroutine s_elemental2
176 procedure(s
), pointer :: p
, q
177 procedure(), pointer :: r
178 external :: s_external
179 p
=> s_external
! OK for a pointer with an explicit interface to be associated with a procedure with an implicit interface
180 r
=> s_module
! OK for a pointer with implicit interface to be associated with a procedure with an explicit interface. See 10.2.2.4 (3)
185 procedure(real) :: f_external
186 external :: s_external
187 procedure(), pointer :: p_s
188 procedure(real), pointer :: p_f
191 !ERROR: Subroutine pointer 'p_s' may not be associated with function designator 'f_external'
193 !ERROR: Function pointer 'p_f' may not be associated with subroutine designator 's_external'
199 real, target
:: x(10, 10)
200 real, pointer :: p(:, :)
202 !ERROR: Pointer 'p' has rank 2 but the number of bounds specified is 1
208 real, target
:: x(10, 10), y(100)
209 real, pointer :: p(:, :)
211 !ERROR: Pointer 'p' has rank 2 but the number of bounds specified is 1
214 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
215 p(1:5,1:5) => x(1:10,::2)
217 !ERROR: Pointer bounds require 25 elements but target has only 20
218 p(1:5,1:5) => x(:,1:2)
219 !OK - rhs has rank 1 and enough elements
220 p(1:5,1:5) => y(1:100:2)
221 !OK - same, but from function result
225 real, pointer :: f(:)
231 integer, pointer :: p(:)
237 type(t
), target
:: y(10,10)
241 p(1:1) => x
%b
! We treat scalars as simply contiguous
243 p(1:1) => y(1,1)%a(1,1)
244 p(1:1) => y(:,1)%a(1,1) ! Rank 1 RHS
245 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
246 p(1:4) => x
%a(::2,::2)
247 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
249 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
250 p(1:100) => y(:,:)%a(1,1)
251 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
252 !ERROR: An array section with a vector subscript may not be a pointer target
257 complex, target
:: x(10,10)
258 complex, pointer :: p(:)
259 real, pointer :: q(:)
262 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
263 q(1:100) => x(:,:)%re
266 ! Check is_contiguous, which is usually the same as when pointer bounds
267 ! remapping is used. If it's not simply contiguous it's not constant so
268 ! an error is reported.
270 integer, pointer :: p(:)
276 type(t
), target
:: y(10,10)
278 logical, parameter :: l1
= is_contiguous(x
%a(:,:))
279 logical, parameter :: l2
= is_contiguous(y(1,1)%a(1,1))
280 !ERROR: Must be a constant value
281 logical, parameter :: l3
= is_contiguous(y(:,1)%a(1,1))
282 !ERROR: Must be a constant value
283 logical, parameter :: l4
= is_contiguous(x
%a(:,v
))
284 !ERROR: Must be a constant value
285 logical, parameter :: l5
= is_contiguous(y(v
,1)%a(1,1))
286 !ERROR: Must be a constant value
287 logical, parameter :: l6
= is_contiguous(p(:))
290 integer, intent(inout
) :: b(..)
291 !ERROR: Must be a constant value
292 integer, parameter :: i
= rank(b
)