156 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! C750 Each bound in the explicit-shape-spec shall be a specification3! expression in which there are no references to specification functions or4! the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT,5! or SAME_TYPE_AS, every specification inquiry reference is a constant6! expression, and the value does not depend on the value of a variable.7!8! C754 Each type-param-value within a component-def-stmt shall be a colon or 9! a specification expression in which there are no references to specification 10! functions or the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF,11! PRESENT, or SAME_TYPE_AS, every specification inquiry reference is a 12! constant expression, and the value does not depend on the value of a variable.13impure function impureFunc()14 integer :: impureFunc15 16 impureFunc = 317end function impureFunc18 19pure function iPureFunc()20 integer :: iPureFunc21 22 iPureFunc = 323end function iPureFunc24 25module m26 real, allocatable :: mVar27end module m28 29subroutine s(iArg, allocArg, pointerArg, arrayArg, ioArg, optionalArg)30! C75031 use m32 implicit logical(l)33 integer, intent(in) :: iArg34 real, allocatable, intent(in) :: allocArg35 real, pointer, intent(in) :: pointerArg36 integer, dimension(:), intent(in) :: arrayArg37 integer, intent(inout) :: ioArg38 real, optional, intent(in) :: optionalArg39 40 ! These declarations are OK since they're not in a derived type41 real :: realVar42 real, volatile :: volatileVar43 real, dimension(merge(1, 2, allocated(allocArg))) :: realVar144 real, dimension(merge(1, 2, associated(pointerArg))) :: realVar245 real, dimension(merge(1, 2, is_contiguous(arrayArg))) :: realVar346 real, dimension(ioArg) :: realVar447 real, dimension(merge(1, 2, present(optionalArg))) :: realVar548 49 ! statement functions referenced below50 iVolatileStmtFunc() = 3 * volatileVar51 iImpureStmtFunc() = 3 * impureFunc()52 iPureStmtFunc() = 3 * iPureFunc()53 54 ! This is OK55 real, dimension(merge(1, 2, allocated(mVar))) :: rVar56 57 integer :: var = 358 !ERROR: Invalid specification expression: reference to impure function 'ivolatilestmtfunc'59 real, dimension(iVolatileStmtFunc()) :: arrayVarWithVolatile60 !ERROR: Invalid specification expression: reference to impure function 'iimpurestmtfunc'61 real, dimension(iImpureStmtFunc()) :: arrayVarWithImpureFunction62 !ERROR: Invalid specification expression: reference to statement function 'ipurestmtfunc'63 real, dimension(iPureStmtFunc()) :: arrayVarWithPureFunction64 real, dimension(iabs(iArg)) :: arrayVarWithIntrinsic65 66 type arrayType67 !ERROR: Invalid specification expression: derived type component or type parameter value not allowed to reference variable 'var'68 real, dimension(var) :: varField69 !ERROR: Invalid specification expression: reference to impure function 'ivolatilestmtfunc'70 real, dimension(iVolatileStmtFunc()) :: arrayFieldWithVolatile71 !ERROR: Invalid specification expression: reference to impure function 'iimpurestmtfunc'72 real, dimension(iImpureStmtFunc()) :: arrayFieldWithImpureFunction73 !ERROR: Invalid specification expression: reference to statement function 'ipurestmtfunc'74 real, dimension(iPureStmtFunc()) :: arrayFieldWithPureFunction75 !ERROR: Invalid specification expression: derived type component or type parameter value not allowed to reference variable 'iarg'76 real, dimension(iabs(iArg)) :: arrayFieldWithIntrinsic77 !ERROR: Invalid specification expression: reference to intrinsic 'allocated' not allowed for derived type components or type parameter values78 real, dimension(merge(1, 2, allocated(allocArg))) :: realField179 !ERROR: Invalid specification expression: reference to intrinsic 'associated' not allowed for derived type components or type parameter values80 real, dimension(merge(1, 2, associated(pointerArg))) :: realField281 !ERROR: Invalid specification expression: non-constant reference to inquiry intrinsic 'is_contiguous' not allowed for derived type components or type parameter values82 real, dimension(merge(1, 2, is_contiguous(arrayArg))) :: realField383 !ERROR: Invalid specification expression: derived type component or type parameter value not allowed to reference variable 'ioarg'84 real, dimension(ioArg) :: realField485 !ERROR: Invalid specification expression: reference to intrinsic 'present' not allowed for derived type components or type parameter values86 real, dimension(merge(1, 2, present(optionalArg))) :: realField587 end type arrayType88 89end subroutine s90 91subroutine s1()92 ! C750, check for a constant specification inquiry that's a type parameter93 ! inquiry which are defined in 9.4.594 type derived(kindParam, lenParam)95 integer, kind :: kindParam = 396 integer, len :: lenParam = 397 end type98 99 contains100 subroutine inner (derivedArg)101 type(derived), intent(in), dimension(3) :: derivedArg102 integer :: localInt103 104 type(derived), parameter :: localderived = derived()105 106 type localDerivedType107 ! OK because the specification inquiry is a constant108 integer, dimension(localDerived%kindParam) :: goodField109 ! OK because the value of lenParam is constant in this context110 integer, dimension(derivedArg%lenParam) :: badField111 end type localDerivedType112 113 ! OK because we're not defining a component114 integer, dimension(derivedArg%kindParam) :: localVar115 end subroutine inner116end subroutine s1117 118subroutine s2(iArg, allocArg, pointerArg, arrayArg, optionalArg)119 ! C754120 integer, intent(in) :: iArg121 real, allocatable, intent(in) :: allocArg122 real, pointer, intent(in) :: pointerArg123 integer, dimension(:), intent(in) :: arrayArg124 real, optional, intent(in) :: optionalArg125 126 type paramType(lenParam)127 integer, len :: lenParam = 4128 end type paramType129 130 type charType131 !ERROR: Invalid specification expression: derived type component or type parameter value not allowed to reference variable 'iarg'132 character(iabs(iArg)) :: fieldWithIntrinsic133 !ERROR: Invalid specification expression: reference to intrinsic 'allocated' not allowed for derived type components or type parameter values134 character(merge(1, 2, allocated(allocArg))) :: allocField135 !ERROR: Invalid specification expression: reference to intrinsic 'associated' not allowed for derived type components or type parameter values136 character(merge(1, 2, associated(pointerArg))) :: assocField137 !ERROR: Invalid specification expression: non-constant reference to inquiry intrinsic 'is_contiguous' not allowed for derived type components or type parameter values138 character(merge(1, 2, is_contiguous(arrayArg))) :: contigField139 !ERROR: Invalid specification expression: reference to intrinsic 'present' not allowed for derived type components or type parameter values140 character(merge(1, 2, present(optionalArg))) :: presentField141 end type charType142 143 type derivedType144 !ERROR: Invalid specification expression: derived type component or type parameter value not allowed to reference variable 'iarg'145 type(paramType(iabs(iArg))) :: fieldWithIntrinsic146 !ERROR: Invalid specification expression: reference to intrinsic 'allocated' not allowed for derived type components or type parameter values147 type(paramType(merge(1, 2, allocated(allocArg)))) :: allocField148 !ERROR: Invalid specification expression: reference to intrinsic 'associated' not allowed for derived type components or type parameter values149 type(paramType(merge(1, 2, associated(pointerArg)))) :: assocField150 !ERROR: Invalid specification expression: non-constant reference to inquiry intrinsic 'is_contiguous' not allowed for derived type components or type parameter values151 type(paramType(merge(1, 2, is_contiguous(arrayArg)))) :: contigField152 !ERROR: Invalid specification expression: reference to intrinsic 'present' not allowed for derived type components or type parameter values153 type(paramType(merge(1, 2, present(optionalArg)))) :: presentField154 end type derivedType155end subroutine s2156