brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.5 KiB · 5af14b4 Raw
126 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12subroutine s1()3  ! C701 (R701) The type-param-value for a kind type parameter shall be a4  ! constant expression.5  !6  ! C702 (R701) A colon shall not be used as a type-param-value except in the7  ! declaration of an entity that has the POINTER or ALLOCATABLE attribute.8  !9  ! C704 (R703) In a declaration-type-spec, every type-param-value that is10  ! not a colon or an asterisk shall be a specification expression.11  !   Section 10.1.11 defines specification expressions12  !13  ! 15.4.2.2(4)(c) A procedure must have an explicit interface if it has a14  ! result that has a nonassumed type parameter value that is not a constant15  ! expression.16  !17  integer, parameter :: constVal = 118  integer :: nonConstVal = 119!PORTABILITY: specification expression refers to local object 'nonconstval' (initialized and saved) [-Wsaved-local-in-spec-expr]20  character(nonConstVal) :: colonString121  character(len=20, kind=constVal + 1) :: constKindString22  character(len=:, kind=constVal + 1), pointer :: constKindString123!ERROR: 'constkindstring2' has a type CHARACTER(KIND=2,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer24  character(len=:, kind=constVal + 1) :: constKindString225!ERROR: Must be a constant value26  character(len=20, kind=nonConstVal) :: nonConstKindString27!ERROR: 'deferredstring' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer28  character(len=:) :: deferredString29!ERROR: 'colonstring2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer30  character(:) :: colonString231  !OK because of the allocatable attribute32  character(:), allocatable :: colonString333!ERROR: 'foo1' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer34  character(:), external :: foo135!ERROR: 'foo2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer36  procedure(character(:)) :: foo237  interface38    function foo3()39!ERROR: 'foo3' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer40      character(:) foo341    end function42  end interface43 44!ERROR: Must have INTEGER type, but is REAL(4)45  character(3.5) :: badParamValue46 47  type derived(typeKind, typeLen)48    integer, kind :: typeKind49    integer, len :: typeLen50    character(typeKind) :: kindValue51    character(typeLen) :: lenValue52  end type derived53 54  type (derived(constVal, 3)) :: constDerivedKind55!ERROR: Value of KIND type parameter 'typekind' must be constant56!PORTABILITY: specification expression refers to local object 'nonconstval' (initialized and saved) [-Wsaved-local-in-spec-expr]57  type (derived(nonConstVal, 3)) :: nonConstDerivedKind58 59  !OK because all type-params are constants60  type (derived(3, constVal)) :: constDerivedLen61 62!PORTABILITY: specification expression refers to local object 'nonconstval' (initialized and saved) [-Wsaved-local-in-spec-expr]63  type (derived(3, nonConstVal)) :: nonConstDerivedLen64!ERROR: 'colonderivedlen' has a type derived(typekind=3_4,typelen=:) with a deferred type parameter but is neither an allocatable nor an object pointer65  type (derived(3, :)) :: colonDerivedLen66!ERROR: Value of KIND type parameter 'typekind' must be constant67!ERROR: 'colonderivedlen1' has a type derived(typekind=:,typelen=:) with a deferred type parameter but is neither an allocatable nor an object pointer68  type (derived( :, :)) :: colonDerivedLen169  type (derived( :, :)), pointer :: colonDerivedLen270  type (derived(4, :)), pointer :: colonDerivedLen371end subroutine s172 73!C70274!ERROR: 'f1' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer75character(:) function f176end function77 78function f279!ERROR: 'f2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer80  character(:) f281end function82 83function f3() result(res)84!ERROR: 'res' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer85  character(:) res86end function87 88!ERROR: 'f4' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer89function f490  implicit character(:)(f)91end function92 93!Not errors.94 95Program d596  Type string(maxlen)97    Integer,Kind :: maxlen98    Character(maxlen) :: value99  End Type100  Type(string(80)) line101  line%value = 'ok'102  Print *,Trim(line%value)103End Program104 105subroutine outer106  integer n107 contains108  character(n) function inner1()109    inner1 = ''110  end function inner1111  function inner2()112    real inner2(n)113  end function inner2114end subroutine outer115 116subroutine s2(dp,dpp)117  !ERROR: 'dp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer118  procedure(character(:)) :: dp119  !ERROR: 'dpp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer120  procedure(character(:)), pointer :: dpp121  !ERROR: 'pp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer122  procedure(character(:)), pointer :: pp123  !ERROR: 'xp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer124  procedure(character(:)) :: xp125end subroutine126