1! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
2! Tests for the last sentence of C1128:
3!A variable-name that is not permitted to appear in a variable definition
4!context shall not appear in a LOCAL or LOCAL_INIT locality-spec.
5
6subroutine s1(arg)
7  real, intent(in) :: arg
8
9  ! This is not OK because "arg" is "intent(in)"
10!ERROR: INTENT IN argument 'arg' not allowed in a locality-spec
11  do concurrent (i=1:5) local(arg)
12  end do
13end subroutine s1
14
15subroutine s2(arg)
16  real, value, intent(in) :: arg
17
18  ! This is not OK even though "arg" has the "value" attribute.  C1128
19  ! explicitly excludes dummy arguments of INTENT(IN)
20!ERROR: INTENT IN argument 'arg' not allowed in a locality-spec
21  do concurrent (i=1:5) local(arg)
22  end do
23end subroutine s2
24
25module m3
26  real, protected :: prot
27  real var
28
29  contains
30    subroutine sub()
31      ! C857 This is OK because of the "protected" attribute only applies to
32      ! accesses outside the module
33      do concurrent (i=1:5) local(prot)
34      end do
35    end subroutine sub
36endmodule m3
37
38subroutine s4()
39  use m3
40
41  ! C857 This is not OK because of the "protected" attribute
42!ERROR: 'prot' may not appear in a locality-spec because it is not definable
43  do concurrent (i=1:5) local(prot)
44  end do
45
46  ! C857 This is OK because of there's no "protected" attribute
47  do concurrent (i=1:5) local(var)
48  end do
49end subroutine s4
50
51subroutine s5()
52  real :: a, b, c, d, e
53
54  associate (a => b + c, d => e)
55    b = 3.0
56    ! C1101 This is OK because 'd' is associated with a variable
57    do concurrent (i=1:5) local(d)
58    end do
59
60    ! C1101 This is not OK because 'a' is not associated with a variable
61!ERROR: 'a' may not appear in a locality-spec because it is not definable
62    do concurrent (i=1:5) local(a)
63    end do
64  end associate
65end subroutine s5
66
67subroutine s6()
68  type point
69    real :: x, y
70  end type point
71
72  type, extends(point) :: color_point
73    integer :: color
74  end type color_point
75
76  type(point), target :: c, d
77  class(point), pointer :: p_or_c
78
79  p_or_c => c
80  select type ( a => p_or_c )
81  type is ( point )
82    ! C1158 This is OK because 'a' is associated with a variable
83    do concurrent (i=1:5) local(a)
84    end do
85  end select
86
87  select type ( a => func() )
88  type is ( point )
89    ! C1158 This is not OK because 'a' is not associated with a variable
90!ERROR: 'a' may not appear in a locality-spec because it is not definable
91    do concurrent (i=1:5) local(a)
92    end do
93  end select
94
95  contains
96    function func()
97      class(point), pointer :: func
98      func => c
99    end function func
100end subroutine s6
101
102module m4
103  real, protected :: prot
104  real var
105endmodule m4
106
107pure subroutine s7()
108  use m4
109
110  ! C1594 This is not OK because we're in a PURE subroutine
111!ERROR: 'var' may not appear in a locality-spec because it is not definable
112  do concurrent (i=1:5) local(var)
113  end do
114end subroutine s7
115
116subroutine s8()
117  integer, parameter :: iconst = 343
118
119!ERROR: 'iconst' may not appear in a locality-spec because it is not definable
120  do concurrent (i=1:5) local(iconst)
121  end do
122end subroutine s8
123