1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
5 use iso_c_binding
, only
: c_ptr
, c_f_pointer
6 type(c_ptr
) :: scalarC
, arrayC(1)
10 type(with_pointer
) :: coindexed
[*]
11 integer, pointer :: scalarIntF
, arrayIntF(:), multiDimIntF(:,:)
12 character(len
=:), pointer :: charDeferredF
14 integer, dimension(2, 2) :: rankTwoArray
15 class(*), pointer :: unlimited
19 type(notBindCType
), pointer :: notBindC
20 character(2), pointer :: c2ptr
21 character(1,4), pointer :: unicodePtr
22 rankTwoArray
= reshape([1, 2, 3, 4], shape(rankTwoArray
))
23 call c_f_pointer(scalarC
, scalarIntF
) ! ok
24 call c_f_pointer(scalarC
, arrayIntF
, [1_8]) ! ok
25 call c_f_pointer(shape
=[1_8], cptr
=scalarC
, fptr
=arrayIntF
) ! ok
26 call c_f_pointer(scalarC
, shape
=[1_8], fptr
=arrayIntF
) ! ok
27 !ERROR: A positional actual argument may not appear after any keyword arguments
28 call c_f_pointer(scalarC
, fptr
=arrayIntF
, [1_8])
29 !ERROR: CPTR= argument to C_F_POINTER() must be a C_PTR
30 call c_f_pointer(j
, scalarIntF
)
31 !ERROR: Rank of dummy argument is 0, but actual argument has rank 1
32 call c_f_pointer(arrayC
, scalarIntF
)
33 !ERROR: SHAPE= argument to C_F_POINTER() must appear when FPTR= is an array
34 call c_f_pointer(scalarC
, arrayIntF
)
35 !ERROR: SHAPE= argument to C_F_POINTER() may not appear when FPTR= is scalar
36 call c_f_pointer(scalarC
, scalarIntF
, [1_8])
37 !ERROR: FPTR= argument to C_F_POINTER() may not have a deferred type parameter
38 call c_f_pointer(scalarC
, charDeferredF
)
39 !ERROR: FPTR= argument to C_F_POINTER() may not be a coindexed object
40 !ERROR: A coindexed object may not be a pointer target
41 call c_f_pointer(scalarC
, coindexed
[0]%p
)
42 !ERROR: FPTR= argument to C_F_POINTER() must have a type
43 call c_f_pointer(scalarC
, null())
44 !ERROR: SHAPE= argument to C_F_POINTER() must have size equal to the rank of FPTR=
45 call c_f_pointer(scalarC
, multiDimIntF
, shape
=[1_8])
46 !ERROR: SHAPE= argument to C_F_POINTER() must be a rank-one array.
47 call c_f_pointer(scalarC
, multiDimIntF
, shape
=rankTwoArray
)
48 !WARNING: FPTR= argument to C_F_POINTER() should not be unlimited polymorphic
49 call c_f_pointer(scalarC
, unlimited
)
50 !PORTABILITY: FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C)
51 call c_f_pointer(scalarC
, notBindC
)
52 !WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable character length CHARACTER(KIND=1,LEN=2_8)
53 call c_f_pointer(scalarC
, c2ptr
)
54 !WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable intrinsic type or kind CHARACTER(KIND=4,LEN=1_8)
55 call c_f_pointer(scalarC
, unicodePtr
)