70 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2! Enforce 18.2.3.33 4program test5 use iso_c_binding, only: c_ptr, c_f_pointer6 type(c_ptr) :: scalarC, arrayC(1)7 type :: with_pointer8 integer, pointer :: p9 end type10 type(with_pointer) :: coindexed[*]11 integer, pointer :: scalarIntF, arrayIntF(:), multiDimIntF(:,:)12 character(len=:), pointer :: charDeferredF13 integer :: j14 integer, dimension(2, 2) :: rankTwoArray15 class(*), pointer :: unlimited16 type :: notBindCType17 integer :: n18 end type19 type(notBindCType), pointer :: notBindC20 character(2), pointer :: c2ptr21 character(1,4), pointer :: unicodePtr22 rankTwoArray = reshape([1, 2, 3, 4], shape(rankTwoArray))23 call c_f_pointer(scalarC, scalarIntF) ! ok24 call c_f_pointer(scalarC, arrayIntF, [1_8]) ! ok25 call c_f_pointer(shape=[1_8], cptr=scalarC, fptr=arrayIntF) ! ok26 call c_f_pointer(scalarC, shape=[1_8], fptr=arrayIntF) ! ok27 !ERROR: A positional actual argument may not appear after any keyword arguments28 call c_f_pointer(scalarC, fptr=arrayIntF, [1_8])29 !ERROR: CPTR= argument to C_F_POINTER() must be a C_PTR30 call c_f_pointer(j, scalarIntF)31 !ERROR: Rank of dummy argument is 0, but actual argument has rank 132 call c_f_pointer(arrayC, scalarIntF)33 !ERROR: SHAPE= argument to C_F_POINTER() must appear when FPTR= is an array34 call c_f_pointer(scalarC, arrayIntF)35 !ERROR: SHAPE= argument to C_F_POINTER() may not appear when FPTR= is scalar36 call c_f_pointer(scalarC, scalarIntF, [1_8])37 !ERROR: FPTR= argument to C_F_POINTER() may not have a deferred type parameter38 call c_f_pointer(scalarC, charDeferredF)39 !ERROR: cosubscript 0 is less than lower cobound 1 for codimension 1 of array40 !ERROR: FPTR= argument to C_F_POINTER() may not be a coindexed object41 !ERROR: A coindexed object may not be a pointer target42 call c_f_pointer(scalarC, coindexed[0]%p)43 !ERROR: FPTR= argument to C_F_POINTER() must have a type44 call c_f_pointer(scalarC, null())45 !ERROR: SHAPE= argument to C_F_POINTER() must have size equal to the rank of FPTR=46 call c_f_pointer(scalarC, multiDimIntF, shape=[1_8])47 !ERROR: SHAPE= argument to C_F_POINTER() must be a rank-one array.48 call c_f_pointer(scalarC, multiDimIntF, shape=rankTwoArray)49 50 !These warnings have been disabled because the C_F_POINTER's restrictions51 !are dependent on the source of the CPTR= argument. Each warning here52 !might be a false positive for a valid program.53 !!WARNING: FPTR= argument to C_F_POINTER() should not be unlimited polymorphic [-Winteroperability]54 call c_f_pointer(scalarC, unlimited)55 !!PORTABILITY: FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C) [-Wportability]56 call c_f_pointer(scalarC, notBindC)57 !!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable character length CHARACTER(KIND=1,LEN=2_8) [-Wcharacter-interoperability]58 call c_f_pointer(scalarC, c2ptr)59 !!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable intrinsic type or kind CHARACTER(KIND=4,LEN=1_8) [-Winteroperability]60 call c_f_pointer(scalarC, unicodePtr)61 62 !ERROR: SHAPE= argument to C_F_POINTER() may not appear when FPTR= is scalar63 !ERROR: LOWER= argument to C_F_POINTER() may not appear when FPTR= is scalar64 call c_f_pointer(scalarC, scalarIntF, [1_8], [0_8])65 !ERROR: LOWER= argument to C_F_POINTER() must be a rank-one array.66 call c_f_pointer(scalarC, arrayIntF, shape=[1_8], lower=rankTwoArray)67 !ERROR: SHAPE= argument to C_F_POINTER() must appear when FPTR= is an array68 call c_f_pointer(scalarC, arrayIntF, lower=[0])69end program70