460 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Wno-portability2! Test 15.5.2.4 constraints and restrictions for non-POINTER non-ALLOCATABLE3! dummy arguments.4 5module m016 type :: t7 end type8 type :: pdt(n)9 integer, len :: n10 end type11 type :: pdtWithDefault(n)12 integer, len :: n = 313 end type14 type :: tbp15 contains16 procedure :: binding => subr0117 end type18 type :: final19 contains20 final :: subr0221 end type22 type :: alloc23 real, allocatable :: a(:)24 end type25 type :: ultimateCoarray26 real, allocatable :: a[:]27 end type28 29 contains30 31 subroutine subr01(this)32 class(tbp), intent(in) :: this33 end subroutine34 subroutine subr02(this)35 type(final), intent(inout) :: this36 end subroutine37 38 subroutine poly(x)39 class(t), intent(in) :: x40 end subroutine41 subroutine polyassumedsize(x)42 class(t), intent(in) :: x(*)43 end subroutine44 subroutine assumedsize(x)45 real :: x(*)46 end subroutine47 subroutine assumedrank(x)48 real :: x(..)49 end subroutine50 subroutine assumedtypeandsize(x)51 type(*) :: x(*)52 end subroutine53 subroutine assumedshape(x)54 real :: x(:)55 end subroutine56 subroutine contiguous(x)57 real, contiguous :: x(:)58 end subroutine59 subroutine intentout(x)60 real, intent(out) :: x61 end subroutine62 subroutine intentout_arr(x)63 real, intent(out) :: x(:)64 end subroutine65 subroutine intentinout(x)66 real, intent(in out) :: x67 end subroutine68 subroutine intentinout_arr(x)69 real, intent(in out) :: x(:)70 end subroutine71 subroutine asynchronous(x)72 real, asynchronous :: x73 end subroutine74 subroutine asynchronous_arr(x)75 real, asynchronous :: x(:)76 end subroutine77 subroutine asynchronousValue(x)78 real, asynchronous, value :: x79 end subroutine80 subroutine volatile(x)81 real, volatile :: x82 end subroutine83 subroutine volatile_arr(x)84 real, volatile :: x(:)85 end subroutine86 subroutine pointer(x)87 real, pointer :: x(:)88 end subroutine89 subroutine valueassumedsize(x)90 real, intent(in) :: x(*)91 end subroutine92 subroutine volatileassumedsize(x)93 real, volatile :: x(*)94 end subroutine95 subroutine volatilecontiguous(x)96 real, volatile :: x(*)97 end subroutine98 99 subroutine test01(x) ! 15.5.2.4(2)100 class(t), intent(in) :: x[*]101 !ERROR: Coindexed polymorphic object may not be associated with a polymorphic dummy argument 'x='102 call poly(x[1])103 end subroutine104 105 subroutine mono(x)106 type(t), intent(in) :: x(*)107 end subroutine108 subroutine test02(x) ! 15.5.2.4(2)109 class(t), intent(in) :: x(*)110 !ERROR: Assumed-size polymorphic array may not be associated with a monomorphic dummy argument 'x='111 call mono(x)112 end subroutine113 114 subroutine typestar(x)115 type(*), intent(in) :: x116 end subroutine117 subroutine test03 ! 15.5.2.4(2)118 type(pdt(0)) :: x119 !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have a parameterized derived type120 call typestar(x)121 end subroutine122 123 subroutine test04 ! 15.5.2.4(2)124 type(tbp) :: x125 !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have type-bound procedure 'binding'126 call typestar(x)127 end subroutine128 129 subroutine test05 ! 15.5.2.4(2)130 type(final) :: x131 !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have derived type 'final' with FINAL subroutine 'subr02'132 call typestar(x)133 end subroutine134 135 subroutine ch2(x)136 character(2), intent(in) :: x137 end subroutine138 subroutine pdtdefault (derivedArg)139 !ERROR: Type parameter 'n' lacks a value and has no default140 type(pdt) :: derivedArg141 end subroutine pdtdefault142 subroutine pdt3 (derivedArg)143 type(pdt(4)) :: derivedArg144 end subroutine pdt3145 subroutine pdt4 (derivedArg)146 type(pdt(*)) :: derivedArg147 end subroutine pdt4148 subroutine pdtWithDefaultDefault (derivedArg)149 type(pdtWithDefault) :: derivedArg150 end subroutine pdtWithDefaultdefault151 subroutine pdtWithDefault3 (derivedArg)152 type(pdtWithDefault(4)) :: derivedArg153 end subroutine pdtWithDefault3154 subroutine pdtWithDefault4 (derivedArg)155 type(pdtWithDefault(*)) :: derivedArg156 end subroutine pdtWithDefault4157 subroutine test06 ! 15.5.2.4(4)158 !ERROR: Type parameter 'n' lacks a value and has no default159 type(pdt) :: vardefault160 type(pdt(3)) :: var3161 type(pdt(4)) :: var4162 type(pdtWithDefault) :: defaultVardefault163 type(pdtWithDefault(3)) :: defaultVar3164 type(pdtWithDefault(4)) :: defaultVar4165 character :: ch1166 !ERROR: Actual argument variable length '1' is less than expected length '2' [-Wshort-character-actual]167 call ch2(ch1)168 !WARNING: Actual argument expression length '0' is less than expected length '2' [-Wshort-character-actual]169 call ch2("")170 call pdtdefault(vardefault)171 !ERROR: Actual argument type 'pdt(n=3_4)' is not compatible with dummy argument type 'pdt'172 call pdtdefault(var3)173 !ERROR: Actual argument type 'pdt(n=4_4)' is not compatible with dummy argument type 'pdt'174 call pdtdefault(var4) ! error175 !ERROR: Actual argument type 'pdt' is not compatible with dummy argument type 'pdt(n=4_4)'176 call pdt3(vardefault)177 !ERROR: Actual argument type 'pdt(n=3_4)' is not compatible with dummy argument type 'pdt(n=4_4)'178 call pdt3(var3)179 call pdt3(var4)180 !ERROR: Actual argument type 'pdt' is not compatible with dummy argument type 'pdt(n=*)'181 call pdt4(vardefault)182 call pdt4(var3)183 call pdt4(var4)184 call pdtWithDefaultdefault(defaultVardefault)185 call pdtWithDefaultdefault(defaultVar3)186 !ERROR: Actual argument type 'pdtwithdefault(n=4_4)' is not compatible with dummy argument type 'pdtwithdefault(n=3_4)'187 call pdtWithDefaultdefault(defaultVar4) ! error188 !ERROR: Actual argument type 'pdtwithdefault(n=3_4)' is not compatible with dummy argument type 'pdtwithdefault(n=4_4)'189 call pdtWithDefault3(defaultVardefault) ! error190 !ERROR: Actual argument type 'pdtwithdefault(n=3_4)' is not compatible with dummy argument type 'pdtwithdefault(n=4_4)'191 call pdtWithDefault3(defaultVar3) ! error192 call pdtWithDefault3(defaultVar4)193 call pdtWithDefault4(defaultVardefault)194 call pdtWithDefault4(defaultVar3)195 call pdtWithDefault4(defaultVar4)196 end subroutine197 198 subroutine out01(x)199 type(alloc) :: x200 end subroutine201 subroutine test07(x) ! 15.5.2.4(6)202 type(alloc) :: x[*]203 !ERROR: Coindexed actual argument with ALLOCATABLE ultimate component '%a' must be associated with a dummy argument 'x=' with VALUE or INTENT(IN) attributes204 call out01(x[1])205 end subroutine206 207 subroutine test08(x) ! 15.5.2.4(13)208 real :: x(1)[*]209 !ERROR: Coindexed scalar actual argument must be associated with a scalar dummy argument 'x='210 call assumedsize(x(1)[1])211 end subroutine212 213 subroutine charray(x)214 character :: x(10)215 end subroutine216 subroutine test09(ashape, polyarray, c, assumed_shape_char) ! 15.5.2.4(14), 15.5.2.11217 real :: x, arr(10)218 real, pointer :: p(:)219 real, pointer :: p_scalar220 character(10), pointer :: char_pointer(:)221 character(*) :: assumed_shape_char(:)222 real :: ashape(:)223 class(t) :: polyarray(*)224 character(10) :: c(:)225 !ERROR: Whole scalar actual argument may not be associated with a dummy argument 'x=' array226 call assumedsize(x)227 !ERROR: Whole scalar actual argument may not be associated with a dummy argument 'x=' array228 call assumedsize(p_scalar)229 !ERROR: Element of pointer array may not be associated with a dummy argument 'x=' array230 call assumedsize(p(1))231 !ERROR: Element of assumed-shape array may not be associated with a dummy argument 'x=' array232 call assumedsize(ashape(1))233 !ERROR: Polymorphic scalar may not be associated with a dummy argument 'x=' array234 call polyassumedsize(polyarray(1))235 call charray(c(1:1)) ! not an error if character236 call charray(char_pointer(1)) ! not an error if character237 call charray(assumed_shape_char(1)) ! not an error if character238 call assumedsize(arr(1)) ! not an error if element in sequence239 call assumedrank(x) ! not an error240 call assumedtypeandsize(x) ! not an error241 end subroutine242 243 subroutine test10(a) ! 15.5.2.4(16)244 real :: scalar, matrix(2,3)245 real :: a(*)246 !ERROR: Scalar actual argument may not be associated with assumed-shape dummy argument 'x='247 call assumedshape(scalar)248 call assumedshape(reshape(matrix,shape=[size(matrix)])) ! ok249 !ERROR: Rank of dummy argument is 1, but actual argument has rank 2250 call assumedshape(matrix)251 !ERROR: Assumed-size array may not be associated with assumed-shape dummy argument 'x='252 call assumedshape(a)253 end subroutine254 255 subroutine test11(in) ! C15.5.2.4(20)256 real, intent(in) :: in257 real :: x258 x = 0.259 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' is not definable260 !BECAUSE: 'in' is an INTENT(IN) dummy argument261 call intentout(in)262 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' is not definable263 !BECAUSE: '3.141590118408203125_4' is not a variable or pointer264 call intentout(3.14159)265 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' is not definable266 !BECAUSE: 'in+1._4' is not a variable or pointer267 call intentout(in + 1.)268 call intentout(x) ! ok269 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' is not definable270 !BECAUSE: '(x)' is not a variable or pointer271 call intentout((x))272 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'count=' is not definable273 !BECAUSE: '2_4' is not a variable or pointer274 call system_clock(count=2)275 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable276 !BECAUSE: 'in' is an INTENT(IN) dummy argument277 call intentinout(in)278 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable279 !BECAUSE: '3.141590118408203125_4' is not a variable or pointer280 call intentinout(3.14159)281 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable282 !BECAUSE: 'in+1._4' is not a variable or pointer283 call intentinout(in + 1.)284 call intentinout(x) ! ok285 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable286 !BECAUSE: '(x)' is not a variable or pointer287 call intentinout((x))288 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'exitstat=' is not definable289 !BECAUSE: '0_4' is not a variable or pointer290 call execute_command_line(command="echo hello", exitstat=0)291 end subroutine292 293 subroutine test12 ! 15.5.2.4(21)294 real :: a(1)295 integer :: j(1)296 j(1) = 1297 !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' is not definable298 !BECAUSE: Variable 'a(int(j,kind=8))' has a vector subscript299 call intentout_arr(a(j))300 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' is not definable301 !BECAUSE: Variable 'a(int(j,kind=8))' has a vector subscript302 call intentinout_arr(a(j))303 !WARNING: Actual argument associated with ASYNCHRONOUS dummy argument 'x=' is not definable [-Wundefinable-asynchronous-or-volatile-actual]304 !BECAUSE: Variable 'a(int(j,kind=8))' has a vector subscript305 call asynchronous_arr(a(j))306 !WARNING: Actual argument associated with VOLATILE dummy argument 'x=' is not definable [-Wundefinable-asynchronous-or-volatile-actual]307 !BECAUSE: Variable 'a(int(j,kind=8))' has a vector subscript308 call volatile_arr(a(j))309 end subroutine310 311 subroutine coarr(x)312 type(ultimateCoarray):: x313 end subroutine314 subroutine volcoarr(x)315 type(ultimateCoarray), volatile :: x316 end subroutine317 subroutine test13(a, b) ! 15.5.2.4(22)318 type(ultimateCoarray) :: a319 type(ultimateCoarray), volatile :: b320 call coarr(a) ! ok321 call volcoarr(b) ! ok322 !ERROR: VOLATILE attribute must match for dummy argument 'x=' when actual argument has a coarray ultimate component '%a'323 call coarr(b)324 !ERROR: VOLATILE attribute must match for dummy argument 'x=' when actual argument has a coarray ultimate component '%a'325 call volcoarr(a)326 end subroutine327 328 subroutine test14(a,b,c,d) ! C1538329 real :: a[*]330 real, asynchronous :: b[*]331 real, volatile :: c[*]332 real, asynchronous, volatile :: d[*]333 call asynchronous(a[1]) ! ok334 call volatile(a[1]) ! ok335 call asynchronousValue(b[1]) ! ok336 call asynchronousValue(c[1]) ! ok337 call asynchronousValue(d[1]) ! ok338 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE339 call asynchronous(b[1])340 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE341 call volatile(b[1])342 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE343 call asynchronous(c[1])344 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE345 call volatile(c[1])346 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE347 call asynchronous(d[1])348 !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE349 call volatile(d[1])350 end subroutine351 352 subroutine test15(assumedrank) ! C1539353 real, pointer :: a(:)354 real, asynchronous :: b(10)355 real, volatile :: c(10)356 real, asynchronous, volatile :: d(10)357 real, asynchronous, volatile :: assumedrank(..)358 call assumedsize(a(::2)) ! ok359 call contiguous(a(::2)) ! ok360 call valueassumedsize(a(::2)) ! ok361 call valueassumedsize(b(::2)) ! ok362 call valueassumedsize(c(::2)) ! ok363 call valueassumedsize(d(::2)) ! ok364 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='365 call volatileassumedsize(b(::2))366 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='367 call volatilecontiguous(b(::2))368 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='369 call volatileassumedsize(c(::2))370 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='371 call volatilecontiguous(c(::2))372 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='373 call volatileassumedsize(d(::2))374 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='375 call volatilecontiguous(d(::2))376 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='377 call volatilecontiguous(assumedrank)378 end subroutine379 380 subroutine test16() ! C1540381 real, pointer :: a(:)382 real, asynchronous, pointer :: b(:)383 real, volatile, pointer :: c(:)384 real, asynchronous, volatile, pointer :: d(:)385 call assumedsize(a) ! ok386 call contiguous(a) ! ok387 call pointer(a) ! ok388 call pointer(b) ! ok389 !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]390 call pointer(c) ! ok391 !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]392 call pointer(d) ! ok393 call valueassumedsize(a) ! ok394 call valueassumedsize(b) ! ok395 call valueassumedsize(c) ! ok396 call valueassumedsize(d) ! ok397 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='398 call volatileassumedsize(b)399 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='400 call volatilecontiguous(b)401 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='402 call volatileassumedsize(c)403 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='404 call volatilecontiguous(c)405 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='406 call volatileassumedsize(d)407 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='408 call volatilecontiguous(d)409 end subroutine410 411 subroutine explicitAsyncContig(x)412 real, asynchronous, intent(in out), contiguous :: x(:)413 end414 subroutine implicitAsyncContig(x)415 real, intent(in out), contiguous :: x(:)416 read(1,id=id,asynchronous="yes") x417 end418 subroutine test17explicit(x)419 real, asynchronous, intent(in out) :: x(:)420 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='421 call explicitAsyncContig(x)422 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='423 call implicitAsyncContig(x)424 end425 subroutine test17implicit(x)426 real, intent(in out) :: x(:)427 read(1,id=id,asynchronous="yes") x428 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='429 call explicitAsyncContig(x)430 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='431 call implicitAsyncContig(x)432 end433 subroutine test17block(x)434 real, intent(in out) :: x(:)435 call explicitAsyncContig(x) ! ok436 call implicitAsyncContig(x) ! ok437 block438 read(1,id=id,asynchronous="yes") x439 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='440 call explicitAsyncContig(x)441 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='442 call implicitAsyncContig(x)443 end block444 end445 subroutine test17internal(x)446 real, intent(in out) :: x(:)447 call explicitAsyncContig(x) ! ok448 call implicitAsyncContig(x) ! ok449 contains450 subroutine internal451 read(1,id=id,asynchronous="yes") x452 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='453 call explicitAsyncContig(x)454 !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='455 call implicitAsyncContig(x)456 end457 end458 459end module460