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: The left-hand side of a pointer assignment is not definable
21 !BECAUSE: Procedure pointer 'p' may not be a coindexed object
28 !ERROR: In assignment to object pointer 'q', the target 's' is a procedure designator
34 a
%p
=> f() ! OK: pointer-valued function
35 !ERROR: Subroutine pointer 'p' may not be associated with function designator 'f'
39 procedure(s
), pointer :: f
44 ! C1030 and 10.2.2.4 - procedure names as target of procedure pointer
45 subroutine s4(s_dummy
)
46 procedure(s
) :: s_dummy
47 procedure(s
), pointer :: p
, q
48 procedure(), pointer :: r
50 external :: s_external
57 subroutine s_internal(i
)
61 subroutine s_module(i
)
67 procedure(f_impure1
), pointer :: p_impure
68 procedure(f_pure1
), pointer :: p_pure
69 !ERROR: Procedure pointer 'p_elemental' may not be ELEMENTAL
70 procedure(f_elemental1
), pointer :: p_elemental
71 procedure(s_impure1
), pointer :: sp_impure
72 procedure(s_pure1
), pointer :: sp_pure
73 !ERROR: Procedure pointer 'sp_elemental' may not be ELEMENTAL
74 procedure(s_elemental1
), pointer :: sp_elemental
76 p_impure
=> f_impure1
! OK, same characteristics
77 p_impure
=> f_pure1
! OK, target may be pure when pointer is not
78 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_elemental1': incompatible procedure attributes: Elemental
79 p_impure
=> f_elemental1
80 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_impureelemental1': incompatible procedure attributes: Elemental
81 p_impure
=> f_ImpureElemental1
! OK, target may be elemental
83 sp_impure
=> s_impure1
! OK, same characteristics
84 sp_impure
=> s_pure1
! OK, target may be pure when pointer is not
85 !ERROR: Procedure pointer 'sp_impure' associated with incompatible procedure designator 's_elemental1': incompatible procedure attributes: Elemental
86 sp_impure
=> s_elemental1
88 !ERROR: PURE procedure pointer 'p_pure' may not be associated with non-PURE procedure designator 'f_impure1'
90 p_pure
=> f_pure1
! OK, same characteristics
91 !ERROR: Procedure pointer 'p_pure' associated with incompatible procedure designator 'f_elemental1': incompatible procedure attributes: Elemental
92 p_pure
=> f_elemental1
93 !ERROR: PURE procedure pointer 'p_pure' may not be associated with non-PURE procedure designator 'f_impureelemental1'
94 p_pure
=> f_impureElemental1
96 !ERROR: PURE procedure pointer 'sp_pure' may not be associated with non-PURE procedure designator 's_impure1'
98 sp_pure
=> s_pure1
! OK, same characteristics
99 !ERROR: Procedure pointer 'sp_pure' associated with incompatible procedure designator 's_elemental1': incompatible procedure attributes: Elemental
100 sp_pure
=> s_elemental1
! OK, target may be elemental when pointer is not
102 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_impure2': incompatible dummy argument #1: incompatible dummy data object intents
103 p_impure
=> f_impure2
104 !ERROR: Function pointer 'p_pure' associated with incompatible function designator 'f_pure2': function results have distinct types: INTEGER(4) vs REAL(4)
106 !ERROR: Function pointer 'p_pure' associated with incompatible function designator 'ccos': function results have distinct types: INTEGER(4) vs COMPLEX(4)
108 !ERROR: Procedure pointer 'p_impure' associated with incompatible procedure designator 'f_elemental2': incompatible procedure attributes: Elemental
109 p_impure
=> f_elemental2
111 !ERROR: Procedure pointer 'sp_impure' associated with incompatible procedure designator 's_impure2': incompatible procedure attributes: BindC
112 sp_impure
=> s_impure2
113 !ERROR: Procedure pointer 'sp_impure' associated with incompatible procedure designator 's_pure2': incompatible dummy argument #1: incompatible dummy data object intents
115 !ERROR: Procedure pointer 'sp_pure' associated with incompatible procedure designator 's_elemental2': incompatible procedure attributes: Elemental
116 sp_pure
=> s_elemental2
118 !ERROR: Function pointer 'p_impure' may not be associated with subroutine designator 's_impure1'
119 p_impure
=> s_impure1
121 !ERROR: Subroutine pointer 'sp_impure' may not be associated with function designator 'f_impure1'
122 sp_impure
=> f_impure1
125 integer function f_impure1(n
)
126 real, intent(in
) :: n
129 pure
integer function f_pure1(n
)
130 real, intent(in
) :: n
133 elemental
integer function f_elemental1(n
)
134 real, intent(in
) :: n
137 impure elemental
integer function f_impureElemental1(n
)
138 real, intent(in
) :: n
139 f_impureElemental
= n
142 integer function f_impure2(n
)
143 real, intent(inout
) :: n
146 pure
real function f_pure2(n
)
147 real, intent(in
) :: n
150 elemental
integer function f_elemental2(n
)
155 subroutine s_impure1(n
)
156 integer, intent(inout
) :: n
159 pure
subroutine s_pure1(n
)
160 integer, intent(inout
) :: n
163 elemental
subroutine s_elemental1(n
)
164 integer, intent(inout
) :: n
168 subroutine s_impure2(n
) bind(c
)
169 integer, intent(inout
) :: n
171 end subroutine s_impure2
172 pure
subroutine s_pure2(n
)
173 integer, intent(out
) :: n
175 end subroutine s_pure2
176 elemental
subroutine s_elemental2(m
,n
)
177 integer, intent(inout
) :: m
, n
179 end subroutine s_elemental2
184 procedure(s
), pointer :: p
, q
185 procedure(), pointer :: r
186 external :: s_external
187 p
=> s_external
! OK for a pointer with an explicit interface to be associated with a procedure with an implicit interface
188 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)
193 procedure(real) :: f_external
194 external :: s_external
195 procedure(), pointer :: p_s
196 procedure(real), pointer :: p_f
199 !Ok: p_s has no interface
201 !Ok: s_external has no interface
207 real, target
:: x(10, 10)
208 real, pointer :: p(:, :)
210 !ERROR: Pointer 'p' has rank 2 but the number of bounds specified is 1
216 real, target
:: x(10, 10), y(100)
217 real, pointer :: p(:, :)
219 !ERROR: Pointer 'p' has rank 2 but the number of bounds specified is 1
222 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
223 p(1:5,1:5) => x(1:10,::2)
225 !ERROR: Pointer bounds require 25 elements but target has only 20
226 p(1:5,1:5) => x(:,1:2)
227 !OK - rhs has rank 1 and enough elements
228 p(1:5,1:5) => y(1:100:2)
229 !OK - same, but from function result
233 real, pointer :: f(:)
239 integer, pointer :: p(:)
245 type(t
), target
:: y(10,10)
249 p(1:1) => x
%b
! We treat scalars as simply contiguous
251 p(1:1) => y(1,1)%a(1,1)
252 p(1:1) => y(:,1)%a(1,1) ! Rank 1 RHS
253 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
254 p(1:4) => x
%a(::2,::2)
255 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
257 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
258 p(1:100) => y(:,:)%a(1,1)
259 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
260 !ERROR: An array section with a vector subscript may not be a pointer target
265 complex, target
:: x(10,10)
266 complex, pointer :: p(:)
267 real, pointer :: q(:)
270 !ERROR: Pointer bounds remapping target must have rank 1 or be simply contiguous
271 q(1:100) => x(:,:)%re
274 ! Check is_contiguous, which is usually the same as when pointer bounds
277 integer, pointer :: p(:)
278 integer, pointer, contiguous
:: pc(:)
284 type(t
), target
:: y(10,10)
286 logical(kind
=merge(1,-1,is_contiguous(x
%a(:,:)))) :: l1
! known true
287 logical(kind
=merge(1,-1,is_contiguous(y(1,1)%a(1,1)))) :: l2
! known true
288 !ERROR: Must be a constant value
289 logical(kind
=merge(-1,-2,is_contiguous(y(:,1)%a(1,1)))) :: l3
! unknown
290 !ERROR: Must be a constant value
291 logical(kind
=merge(-1,-2,is_contiguous(y(:,1)%a(1,1)))) :: l4
! unknown
292 logical(kind
=merge(-1,1,is_contiguous(x
%a(:,v
)))) :: l5
! known false
293 !ERROR: Must be a constant value
294 logical(kind
=merge(-1,-2,is_contiguous(y(v
,1)%a(1,1)))) :: l6
! unknown
295 !ERROR: Must be a constant value
296 logical(kind
=merge(-1,-2,is_contiguous(p(:)))) :: l7
! unknown
297 logical(kind
=merge(1,-1,is_contiguous(pc(:)))) :: l8
! known true
298 logical(kind
=merge(-1,1,is_contiguous(pc(1:10:2)))) :: l9
! known false
299 logical(kind
=merge(-1,1,is_contiguous(pc(10:1:-1)))) :: l10
! known false
300 logical(kind
=merge(1,-1,is_contiguous(pc(1:10:1)))) :: l11
! known true
301 logical(kind
=merge(-1,1,is_contiguous(pc(10:1:-1)))) :: l12
! known false
302 !ERROR: Must be a constant value
303 logical(kind
=merge(-1,1,is_contiguous(pc(::-1)))) :: l13
! unknown (could be empty)
304 logical(kind
=merge(1,-1,is_contiguous(y(1,1)%a(::-1,1)))) :: l14
! known true (empty)
305 logical(kind
=merge(1,-1,is_contiguous(y(1,1)%a(1,::-1)))) :: l15
! known true (empty)
308 integer, intent(inout
) :: b(..)
309 !ERROR: Must be a constant value
310 integer, parameter :: i
= rank(b
)
314 external :: s_external
315 procedure(), pointer :: ptr
316 !Ok - don't emit an error about incompatible Subroutine attribute
322 procedure(real), pointer :: ptr
324 !ERROR: Statement function 'sf' may not be the target of a pointer assignment