brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · e7c0fd8 Raw
115 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Test 15.7 C1594 - prohibited assignments in pure subprograms3 4module used5  real :: useassociated6end module7 8module m9  type :: t10    sequence11    real :: a12  end type13  type(t), target :: x14  type :: hasPtr15    real, pointer :: p16  end type17  type :: hasCoarray18    real, allocatable :: co[:]19  end type20  type :: hasHiddenPtr21    type(hasPtr), allocatable :: a22  end type23 contains24  integer pure function purefunc(x)25    integer, intent(in) :: x26    purefunc = x27  end function28  integer pure function f00(p0)29    procedure(purefunc) :: p030    f00 = p0(1)31  end function32  pure function test(ptr, in, hpd, hhpd)33    use used34    type(t), pointer :: ptr, ptr235    type(t), target, intent(in) :: in36    type(t), target :: y, z37    type(hasPtr) :: hp38    type(hasPtr), intent(in) :: hpd39    type(hasHiddenPtr) :: hhp40    type(hasHiddenPtr), intent(in) :: hhpd41    type(hasPtr), allocatable :: alloc42    type(hasHiddenPtr), allocatable :: hpAlloc43    !ERROR: Pointer 'hcp' may not have a coarray potential component '%co'44    type(hasCoarray), pointer :: hcp45    type(hasCoarray), allocatable :: hca46    integer :: n47    common /block/ y48    external :: extfunc49    !ERROR: Left-hand side of assignment is not definable50    !BECAUSE: 'x' may not be defined in pure subprogram 'test' because it is host-associated51    x%a = 0.52    !ERROR: Left-hand side of assignment is not definable53    !BECAUSE: 'y' may not be defined in pure subprogram 'test' because it is in a COMMON block54    y%a = 0. ! C1594(1)55    !ERROR: Left-hand side of assignment is not definable56    !BECAUSE: 'useassociated' may not be defined in pure subprogram 'test' because it is USE-associated57    useassociated = 0.  ! C1594(1)58    !ERROR: Left-hand side of assignment is not definable59    !BECAUSE: 'ptr' is externally visible via 'ptr' and not definable in a pure subprogram60    ptr%a = 0. ! C1594(1)61    !ERROR: Left-hand side of assignment is not definable62    !BECAUSE: 'in' is an INTENT(IN) dummy argument63    in%a = 0. ! C1594(1)64    !ERROR: Left-hand side of assignment is not definable65    !BECAUSE: A pure subprogram may not define the coindexed object 'hca%co[1_8]'66    hca%co[1] = 0. ! C1594(1)67    !ERROR: The left-hand side of a pointer assignment is not definable68    !BECAUSE: 'ptr' may not be defined in pure subprogram 'test' because it is a POINTER dummy argument of a pure function69    ptr => z ! C1594(2)70    !ERROR: 'ptr' may not appear in NULLIFY71    !BECAUSE: 'ptr' may not be defined in pure subprogram 'test' because it is a POINTER dummy argument of a pure function72    nullify(ptr) ! C1594(2), 19.6.873    !ERROR: A pure subprogram may not use 'ptr' as the target of pointer assignment because it is a POINTER dummy argument of a pure function74    ptr2 => ptr ! C1594(3)75    !ERROR: A pure subprogram may not use 'in' as the target of pointer assignment because it is an INTENT(IN) dummy argument76    ptr2 => in ! C1594(3)77    !ERROR: A pure subprogram may not use 'y' as the target of pointer assignment because it is in a COMMON block78    ptr2 => y ! C1594(2)79    !ERROR: Externally visible object 'block' may not be associated with pointer component 'p' in a pure procedure80    n = size([hasPtr(y%a)]) ! C1594(4)81    !ERROR: Externally visible object 'x' may not be associated with pointer component 'p' in a pure procedure82    n = size([hasPtr(x%a)]) ! C1594(4)83    !ERROR: Externally visible object 'ptr' may not be associated with pointer component 'p' in a pure procedure84    n = size([hasPtr(ptr%a)]) ! C1594(4)85    !ERROR: Externally visible object 'in' may not be associated with pointer component 'p' in a pure procedure86    n = size([hasPtr(in%a)]) ! C1594(4)87    !ERROR: A pure subprogram may not copy the value of 'hpd' because it is an INTENT(IN) dummy argument and has the POINTER potential subobject component '%p'88    hp = hpd ! C1594(5)89    !ERROR: A pure subprogram may not copy the value of 'hpd' because it is an INTENT(IN) dummy argument and has the POINTER potential subobject component '%p'90    allocate(alloc, source=hpd)91    !ERROR: A pure subprogram may not copy the value of 'hhpd' because it is an INTENT(IN) dummy argument and has the POINTER potential subobject component '%a%p'92    hhp = hhpd93    !ERROR: A pure subprogram may not copy the value of 'hhpd' because it is an INTENT(IN) dummy argument and has the POINTER potential subobject component '%a%p'94    allocate(hpAlloc, source=hhpd)95    !ERROR: Actual procedure argument for dummy argument 'p0=' of a PURE procedure must have an explicit interface96    n = f00(extfunc)97   contains98    pure subroutine internal99      type(hasPtr) :: localhp100      !ERROR: Left-hand side of assignment is not definable101      !BECAUSE: 'z' may not be defined in pure subprogram 'internal' because it is host-associated102      z%a = 0.103      !ERROR: Externally visible object 'z' may not be associated with pointer component 'p' in a pure procedure104      localhp = hasPtr(z%a)105    end subroutine106  end function107  pure subroutine test2(hpd, hhpd)108    use used109    type(hasHiddenPtr), intent(in out) :: hpd, hhpd[*]110    hpd = hhpd ! ok111    !ERROR: A pure subprogram may not copy the value of 'hhpd' because it is coindexed and has the POINTER potential subobject component '%a%p'112    hpd = hhpd[1]113  end subroutine114end module115