255 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2! Test 15.5.2.5 constraints and restrictions for POINTER & ALLOCATABLE3! arguments when both sides of the call have the same attributes.4 5module m6 7 type :: t8 end type9 type, extends(t) :: t210 end type11 type :: pdt(n)12 integer, len :: n13 end type14 15 type(t), pointer :: mp(:), mpmat(:,:)16 type(t), allocatable :: ma(:), mamat(:,:)17 class(t), pointer :: pp(:)18 class(t), allocatable :: pa(:)19 class(t2), pointer :: pp2(:)20 class(t2), allocatable :: pa2(:)21 class(*), pointer :: up(:)22 class(*), allocatable :: ua(:)23 !ERROR: An assumed (*) type parameter may be used only for a (non-statement function) dummy argument, associate name, character named constant, or external function result24 type(pdt(*)), pointer :: amp(:)25 !ERROR: An assumed (*) type parameter may be used only for a (non-statement function) dummy argument, associate name, character named constant, or external function result26 type(pdt(*)), allocatable :: ama(:)27 type(pdt(:)), pointer :: dmp(:)28 type(pdt(:)), allocatable :: dma(:)29 type(pdt(1)), pointer :: nmp(:)30 type(pdt(1)), allocatable :: nma(:)31 32 contains33 34 subroutine smp(x)35 type(t), pointer :: x(:)36 end subroutine37 subroutine sma(x)38 type(t), allocatable :: x(:)39 end subroutine40 subroutine spp(x)41 class(t), pointer :: x(:)42 end subroutine43 subroutine spa(x)44 class(t), allocatable :: x(:)45 end subroutine46 subroutine sup(x)47 class(*), pointer :: x(:)48 end subroutine49 subroutine sua(x)50 class(*), allocatable :: x(:)51 end subroutine52 subroutine samp(x)53 type(pdt(*)), pointer :: x(:)54 end subroutine55 subroutine sama(x)56 type(pdt(*)), allocatable :: x(:)57 end subroutine58 subroutine sdmp(x)59 type(pdt(:)), pointer :: x(:)60 end subroutine61 subroutine sdma(x)62 type(pdt(:)), allocatable :: x(:)63 end subroutine64 subroutine snmp(x)65 type(pdt(1)), pointer :: x(:)66 end subroutine67 subroutine snma(x)68 type(pdt(1)), allocatable :: x(:)69 end subroutine70 71 subroutine test72 call smp(mp) ! ok73 call sma(ma) ! ok74 call spp(pp) ! ok75 call spa(pa) ! ok76 !PORTABILITY: If a POINTER or ALLOCATABLE actual argument is polymorphic, the corresponding dummy argument should also be so [-Wpolymorphic-actual-allocatable-or-pointer-to-monomorphic-dummy]77 call smp(pp)78 !PORTABILITY: If a POINTER or ALLOCATABLE actual argument is polymorphic, the corresponding dummy argument should also be so [-Wpolymorphic-actual-allocatable-or-pointer-to-monomorphic-dummy]79 call sma(pa)80 !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is polymorphic, both must be so81 call spp(mp)82 !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is polymorphic, both must be so83 call spa(ma)84 !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is unlimited polymorphic, both must be so85 call sup(pp)86 !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is unlimited polymorphic, both must be so87 call sua(pa)88 !ERROR: Actual argument type 'CLASS(*)' is not compatible with dummy argument type 'CLASS(t)'89 !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic90 call spp(up)91 !ERROR: Actual argument type 'CLASS(*)' is not compatible with dummy argument type 'CLASS(t)'92 call spa(ua)93 !ERROR: POINTER or ALLOCATABLE dummy and actual arguments must have the same declared type and kind94 call spp(pp2)95 !ERROR: POINTER or ALLOCATABLE dummy and actual arguments must have the same declared type and kind96 call spa(pa2)97 !ERROR: Rank of dummy argument is 1, but actual argument has rank 298 !ERROR: Pointer has rank 1 but target has rank 299 call smp(mpmat)100 !ERROR: Rank of dummy argument is 1, but actual argument has rank 2101 call sma(mamat)102 call sdmp(dmp) ! ok103 call sdma(dma) ! ok104 call snmp(nmp) ! ok105 call snma(nma) ! ok106 call samp(nmp) ! ok107 call sama(nma) ! ok108 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE109 call sdmp(nmp)110 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE111 call sdma(nma)112 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE113 call snmp(dmp)114 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE115 call snma(dma)116 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE117 call samp(dmp)118 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE119 call sama(dma)120 end subroutine121 122end module123 124module m2125 126 character(len=10), allocatable :: t1, t2, t3, t4127 character(len=:), allocatable :: t5, t6, t7, t8(:)128 129 character(len=10), pointer :: p1130 character(len=:), pointer :: p2131 132 integer, allocatable :: x(:)133 134 contains135 136 subroutine sma(a)137 character(len=:), allocatable, intent(in) :: a138 end139 140 subroutine sma2(a)141 character(len=10), allocatable, intent(in) :: a142 end143 144 subroutine smp(p)145 character(len=:), pointer, intent(in) :: p146 end147 148 subroutine smp2(p)149 character(len=10), pointer, intent(in) :: p150 end151 152 subroutine smb(b)153 integer, allocatable, intent(in) :: b(:)154 end155 156 function return_deferred_length_ptr()157 character(len=:), pointer :: return_deferred_length_ptr158 return_deferred_length_ptr => p2159 end function160 161 function return_explicit_length_ptr(n)162 integer :: n163 character(len=n), pointer :: return_explicit_length_ptr164 return_explicit_length_ptr => p2(1:n)165 end function166 167 subroutine test()168 169 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE170 call sma(t1)171 172 call sma2(t1) ! ok173 174 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE175 call smp(p1)176 177 call smp2(p1) ! ok178 179 call smp(return_deferred_length_ptr()) ! ok180 181 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE182 call smp2(return_deferred_length_ptr())183 184 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE185 call smp(return_explicit_length_ptr(10))186 187 call smp2(return_explicit_length_ptr(10)) ! ok188 189 !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument190 call sma(t2(:))191 192 !ERROR: 't3' is not a callable procedure193 call sma(t3(1))194 195 !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument196 call sma(t4(1:2))197 198 call sma(t5) ! ok199 200 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE201 call sma2(t5)202 203 call smp(p2) ! ok204 205 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE206 call smp2(p2)207 208 !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument209 call sma(t5(:))210 211 !ERROR: 't6' is not a callable procedure212 call sma(t6(1))213 214 !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument215 call sma(t7(1:2))216 217 !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument218 call sma(t8(1))219 220 !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument221 call smb(x(:))222 223 !ERROR: Rank of dummy argument is 1, but actual argument has rank 0224 !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument225 call smb(x(2))226 227 !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument228 call smb(x(1:2))229 230 end subroutine231 232end module233 234module test235 type t(l)236 integer, len :: l237 character(l) :: c238 end type239 240 contains241 242 subroutine bar(p)243 type(t(:)), allocatable :: p(:)244 end subroutine245 246 subroutine foo247 type(t(10)), allocatable :: p(:)248 249 !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE250 call bar(p)251 252 end subroutine253 254end module255