summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/forall_4.f90
blob: e71e0b847f5ed780770caf128f06edef94aeddba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
! { dg-do run }
! Tests the fix for PR25072, in which mask expressions
! that start with an internal or intrinsic function 
! reference would give a syntax error.
!
! The fix for PR28119 is tested as well; here, the forall
! statement could not be followed by another statement on
! the same line.
!
! Contributed by Paul Thomas  <pault@gcc.gnu.org>
!
module foo
  integer, parameter :: n = 4
contains
  pure logical function foot (i)
    integer, intent(in) :: i
    foot = (i == 2) .or. (i == 3)
  end function foot
end module foo

  use foo
  integer :: i, a(n)
  logical :: s(n)
  s = (/(foot (i), i=1, n)/)

! Check that non-mask case is still OK and the fix for PR28119
  a = 0
  forall (i=1:n) a(i) = i ; if (any (a .ne. (/1,2,3,4/))) call abort ()

! Now a mask using a function with an explicit interface
! via use association.
  a = 0
  forall (i=1:n, foot (i)) a(i) = i
  if (any (a .ne. (/0,2,3,0/))) call abort ()

! Now an array variable mask
  a = 0
  forall (i=1:n, .not. s(i)) a(i) = i
  if (any (a .ne. (/1,0,0,4/))) call abort ()

! This was the PR - an internal function mask
  a = 0
  forall (i=1:n, t (i)) a(i) = i
  if (any (a .ne. (/0,2,0,4/))) call abort ()

! Check that an expression is OK - this also gave a syntax
! error
  a = 0
  forall (i=1:n, mod (i, 2) == 0) a(i) = i
  if (any (a .ne. (/0,2,0,4/))) call abort ()

! And that an expression that used to work is OK
  a = 0
  forall (i=1:n, s (i) .or. t(i)) a(i) = w (i)
  if (any (a .ne. (/0,3,2,1/))) call abort ()

contains
  pure logical function t(i)
    integer, intent(in) :: i
    t = (mod (i, 2) == 0)
  end function t
  pure integer function w(i)
    integer, intent(in) :: i
    w = 5 - i
  end function w
end
! { dg-final { cleanup-modules "foo" } }