view gcc/testsuite/gfortran.dg/do_check_6.f90 @ 128:fe568345ddd5

fix CbC-example
author mir3636
date Wed, 11 Apr 2018 19:32:28 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line source

! { dg-do compile }
!
! PR fortran/54958
!
module m
  integer, protected :: i
  integer :: j
end module m

subroutine test1()
  use m
  implicit none
  integer :: A(5)
  ! Valid: data-implied-do (has a scope of the statement or construct)
  DATA (A(i), i=1,5)/5*42/ ! OK

  ! Valid: ac-implied-do (has a scope of the statement or construct)
  print *, [(i, i=1,5 )] ! OK

  ! Valid: index-name (has a scope of the statement or construct)
  forall (i = 1:5) ! OK
  end forall

  ! Valid: index-name (has a scope of the statement or construct)
  do concurrent (i = 1:5) ! OK
  end do

  ! Invalid: io-implied-do
  print *, (i, i=1,5 ) ! { dg-error "PROTECTED and can not appear in a variable definition context .iterator variable." }

  ! Invalid: do-variable in a do-stmt
  do i = 1, 5 ! { dg-error "PROTECTED and can not appear in a variable definition context .iterator variable." }
  end do
end subroutine test1

subroutine test2(i)
  implicit none
  integer, intent(in) :: i
  integer :: A(5)
  ! Valid: data-implied-do (has a scope of the statement or construct)
  DATA (A(i), i=1,5)/5*42/ ! OK

  ! Valid: ac-implied-do (has a scope of the statement or construct)
  print *, [(i, i=1,5 )] ! OK

  ! Valid: index-name (has a scope of the statement or construct)
  forall (i = 1:5) ! OK
  end forall

  ! Valid: index-name (has a scope of the statement or construct)
  do concurrent (i = 1:5) ! OK
  end do

  ! Invalid: io-implied-do
  print *, (i, i=1,5 ) ! { dg-error "INTENT.IN. in variable definition context .iterator variable." }

  ! Invalid: do-variable in a do-stmt
  do i = 1, 5 ! { dg-error "INTENT.IN. in variable definition context .iterator variable." }
  end do
end subroutine test2

pure subroutine test3()
  use m
  implicit none
  integer :: A(5)
  !DATA (A(j), j=1,5)/5*42/ ! Not allowed in pure

  ! Valid: ac-implied-do (has a scope of the statement or construct)
  A = [(j, j=1,5 )] ! OK

  ! Valid: index-name (has a scope of the statement or construct)
  forall (j = 1:5) ! OK
  end forall

  ! Valid: index-name (has a scope of the statement or construct)
  do concurrent (j = 1:5) ! OK
  end do

  ! print *, (j, j=1,5 ) ! I/O not allowed in PURE

  ! Invalid: do-variable in a do-stmt
  do j = 1, 5 ! { dg-error "variable definition context .iterator variable. at .1. in PURE procedure" }
  end do
end subroutine test3