205 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Tests for the 14 items that specify a "specification expression" in section3! 10.1.114 5! a constant or subobject of a constant,6subroutine s1()7 type dType8 integer :: field9 end type dType10 11 type(dType), parameter :: dConst = dType(3)12 real, dimension(3) :: realVar113 real, dimension(dConst%field) :: realVar214end subroutine s115 16! an object designator with a base object that is a dummy argument that has 17! neither the OPTIONAL nor the INTENT (OUT) attribute,18subroutine s2(inArg, inoutArg, outArg, optArg)19 integer, intent(in) :: inArg20 integer, intent(inout) :: inoutArg21 integer, intent(out) :: outArg22 integer, intent(in), optional :: optArg23 real, dimension(inArg) :: realVar124 real, dimension(inoutArg) :: realVar225 !ERROR: Invalid specification expression: reference to INTENT(OUT) dummy argument 'outarg'26 real, dimension(outArg) :: realVar327 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optarg'28 real, dimension(optArg) :: realVar429 30 outArg = 331 block32 !PORTABILITY: specification expression refers to host-associated INTENT(OUT) dummy argument 'outarg' [-Whost-associated-intent-out-in-spec-expr]33 real a(outArg)34 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optarg'35 real b(optArg)36 end block37 contains38 subroutine s2inner39 !PORTABILITY: specification expression refers to host-associated INTENT(OUT) dummy argument 'outarg' [-Whost-associated-intent-out-in-spec-expr]40 real a(outArg)41 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optarg'42 real b(optArg)43 end44end subroutine s245 46! an object designator with a base object that is in a common block,47subroutine s3()48 integer :: intVar49 common intCommonVar50 real, dimension(intCommonVar) :: realVar51end subroutine s352 53! an object designator with a base object that is made accessible by54! use or host association,55module m456 integer :: intVar57end module m458 59subroutine s4()60 use m461 real, dimension(intVar) :: realVar62end subroutine s463 64! an array constructor where each element and each scalar-int-expr of 65! each ac-implied-do-control is a restricted expression,66subroutine s5()67 real, dimension(storage_size([1,2])) :: realVar68end subroutine s569 70! a structure constructor where each component is a restricted expression,71subroutine s6()72 type :: dType73 integer :: field174 integer :: field275 end type dType76 77 real, dimension(storage_size(dType(1, 2))) :: realArray78end subroutine s679 80! a specification inquiry where each designator or argument is81! (a) a restricted expression or82subroutine s7a()83 real, dimension(3) :: realArray184 real, dimension(size(realArray1)) :: realArray285end subroutine s7a86 87! a specification inquiry where each designator or argument is88! (b) a variable that is not an optional dummy argument, and whose89! properties inquired about are not90! (i) dependent on the upper bound of the last dimension of an 91! assumed-size array,92subroutine s7bi(assumedArg)93 integer, dimension(2, *) :: assumedArg94 real, dimension(ubound(assumedArg, 1)) :: realArray195 !ERROR: DIM=2 dimension is out of range for rank-2 assumed-size array96 real, dimension(ubound(assumedArg, 2)) :: realArray297end subroutine s7bi98 99! a specification inquiry where each designator or argument is100! (b) a variable that is not an optional dummy argument, and whose101! properties inquired about are not102! (ii) deferred, or103subroutine s7bii(dummy)104 character(len=:), pointer :: dummy105 ! Should be an error since "dummy" is deferred, but all compilers handle it106 real, dimension(len(dummy)) :: realArray107end subroutine s7bii108 109! a specification inquiry where each designator or argument is110! (b) a variable that is not an optional dummy argument, and whose111! properties inquired about are not112! (iii) defined by an expression that is not a restricted expression,113subroutine s7biii(x, y)114 real, intent(out) :: x(:)115 real, optional :: y(:)116 integer, parameter :: localConst = 5117 integer :: local = 5118 ! OK, since "localConst" is a constant119 real, dimension(localConst) :: realArray1120 !PORTABILITY: specification expression refers to local object 'local' (initialized and saved) [-Wsaved-local-in-spec-expr]121 real, dimension(local) :: realArray2122 real, dimension(size(realArray1)) :: realArray3 ! ok123 real, dimension(size(x)) :: realArray4 ! ok124 real, dimension(merge(1,2,present(y))) :: realArray5 ! ok125 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'y'126 real, dimension(size(y)) :: realArray6127end subroutine s7biii128 129! a specification inquiry that is a constant expression,130subroutine s8()131 integer :: iVar132 real, dimension(bit_size(iVar)) :: realArray133end subroutine s8134 135! a reference to the intrinsic function PRESENT,136subroutine s9(optArg)137 integer, optional :: optArg138 real, dimension(merge(3, 4, present(optArg))) :: realArray139end subroutine s9140 141! a reference to any other standard intrinsic function where each142! argument is a restricted expression,143subroutine s10()144 integer :: iVar145 real, dimension(bit_size(iVar)) :: realArray146end subroutine s10147 148! a reference to a transformational function from the intrinsic module 149! IEEE_ARITHMETIC, IEEE_EXCEPTIONS, or ISO_C_BINDING, where each argument 150! is a restricted expression,151subroutine s11()152 use ieee_exceptions153 real, dimension(merge(3, 4, ieee_support_halting(ieee_invalid))) :: realArray154end subroutine s11155 156! a reference to a specification function where each argument is a 157! restricted expression,158module m12159 contains160 pure function specFunc(arg)161 integer, intent(in) :: arg162 integer :: specFunc163 specFunc = 3 + arg164 end function specFunc165end module m12166 167subroutine s12()168 use m12169 real, dimension(specFunc(2)) :: realArray170end subroutine s12171 172! a type parameter of the derived type being defined,173subroutine s13()174 type :: dtype(param)175 integer, len :: param176 real, dimension(param) :: realField177 end type dtype178end subroutine s13179 180! an ac-do-variable within an array constructor where each 181! scalar-int-expr of the corresponding ac-implied-do-control is a restricted 182! expression, or183subroutine s14()184 real, dimension(5) :: realField = [(i, i = 1, 5)]185end subroutine s14186 187! a restricted expression enclosed in parentheses,where each subscript, 188! section subscript, substring starting point, substring ending point, and 189! type parameter value is a restricted expression190subroutine s15()191 type :: dtype(param)192 integer, len :: param193 real, dimension((param + 2)) :: realField194 end type dtype195end subroutine s15196 197! Regression test: don't get confused by host association198subroutine s16(n)199 integer :: n200 contains201 subroutine inner(r)202 real, dimension(n) :: r203 end subroutine204end subroutine s16205