121 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Miscellaneous constraint and requirement checking on intrinsics3program test_size4 real :: scalar5 real, dimension(5, 5) :: array6 call test(array, array, array)7 contains8 subroutine test(arg, assumedRank, poly)9 real, dimension(5, *) :: arg10 real, dimension(..) :: assumedRank11 class(*) :: poly(5, *)12 !ERROR: A dim= argument is required for 'size' when the array is assumed-size13 print *, size(arg)14 print *, size(arg, dim=1) ! ok15 select type (poly)16 type is (real)17 !ERROR: A dim= argument is required for 'size' when the array is assumed-size18 print *, size(poly)19 print *, size(poly, dim=1) ! ok20 end select21 !ERROR: A dim= argument is required for 'ubound' when the array is assumed-size22 print *, ubound(arg)23 print *, ubound(arg, dim=1) ! ok24 select type (poly)25 type is (real)26 !ERROR: A dim= argument is required for 'ubound' when the array is assumed-size27 print *, ubound(poly)28 print *, ubound(poly, dim=1) ! ok29 end select30 !ERROR: The 'source=' argument to the intrinsic function 'shape' may not be assumed-size31 print *, shape(arg)32 select type (poly)33 type is (real)34 !ERROR: The 'source=' argument to the intrinsic function 'shape' may not be assumed-size35 print *, shape(poly)36 end select37 !ERROR: The 'harvest=' argument to the intrinsic procedure 'random_number' may not be assumed-size38 call random_number(arg)39 !ERROR: 'array=' argument has unacceptable rank 040 print *, lbound(scalar)41 !ERROR: 'array=' argument has unacceptable rank 042 print *, size(scalar)43 !ERROR: 'array=' argument has unacceptable rank 044 print *, ubound(scalar)45 !ERROR: DIM=0 dimension must be positive46 print *, lbound(arg, 0)47 !ERROR: DIM=0 dimension must be positive48 print *, lbound(assumedRank, 0)49 !ERROR: DIM=666 dimension is too large for any array (maximum rank 15)50 print *, lbound(assumedRank, 666)51 !ERROR: DIM=0 dimension must be positive52 print *, ubound(arg, 0)53 !ERROR: DIM=2 dimension is out of range for rank-2 assumed-size array54 print *, ubound(arg, 2)55 !ERROR: DIM=0 dimension must be positive56 print *, ubound(assumedRank, 0)57 !ERROR: DIM=666 dimension is too large for any array (maximum rank 15)58 print *, ubound(assumedRank, 666)59 select rank(assumedRank)60 rank(1)61 !ERROR: DIM=2 dimension is out of range for rank-1 array62 print *, lbound(assumedRank, dim=2)63 !ERROR: DIM=2 dimension is out of range for rank-1 array64 print *, ubound(assumedRank, dim=2)65 rank(*)66 !ERROR: A dim= argument is required for 'size' when the array is assumed-size67 print *, size(assumedRank)68 !ERROR: A dim= argument is required for 'ubound' when the array is assumed-size69 print *, ubound(assumedRank)70 !ERROR: The 'source=' argument to the intrinsic function 'shape' may not be assumed-size71 print *, shape(assumedRank)72 !ERROR: The 'harvest=' argument to the intrinsic procedure 'random_number' may not be assumed-size73 call random_number(assumedRank)74 !ERROR: DIM=0 dimension must be positive75 print *, lbound(assumedRank, 0)76 !ERROR: DIM=0 dimension must be positive77 print *, ubound(assumedRank, 0)78 !ERROR: DIM=1 dimension is out of range for rank-1 assumed-size array79 print *, ubound(assumedRank, 1)80 !ERROR: DIM=2 dimension is out of range for rank-1 array81 print *, lbound(assumedRank, dim=2)82 !ERROR: DIM=2 dimension is out of range for rank-1 array83 print *, ubound(assumedRank, dim=2)84 end select85 ! But these cases are fine:86 print *, size(arg, dim=1)87 print *, ubound(arg, dim=1)88 print *, lbound(arg)89 print *, size(array)90 print *, ubound(array)91 print *, lbound(array)92 print *, size(arg(:,1))93 print *, ubound(arg(:,1))94 print *, shape(scalar)95 print *, shape(arg(:,1))96 print *, lbound(assumedRank, dim=2) ! can't check until run time97 print *, ubound(assumedRank, dim=2)98 select rank(assumedRank)99 rank(3)100 print *, lbound(assumedRank, dim=2)101 print *, ubound(assumedRank, dim=2)102 rank(*)103 print *, lbound(assumedRank, dim=1)104 rank default105 print *, lbound(assumedRank, dim=2)106 print *, ubound(assumedRank, dim=2)107 end select108 contains109 subroutine inner110 !ERROR: A dim= argument is required for 'size' when the array is assumed-size111 print *, size(arg)112 print *, size(arg, dim=1) ! ok113 !ERROR: A dim= argument is required for 'ubound' when the array is assumed-size114 print *, ubound(arg)115 print *, ubound(arg, dim=1) ! ok116 !ERROR: The 'source=' argument to the intrinsic function 'shape' may not be assumed-size117 print *, shape(arg)118 end119 end subroutine120end121