1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Test 15.7 (C1583-C1590, C1592-C1599) constraints and restrictions
4 ! (C1591 is tested in call11.f90; C1594 in call12.f90.)
15 class(t
), allocatable
:: a
18 real, volatile, target
:: volatile
21 ! Ensure no errors for "ignored" declarations in a pure interface.
22 ! These declarations do not contribute to the characteristics of
23 ! the procedure and must not elicit spurious errors about being used
24 ! in a pure procedure.
42 type(impureFinal
) :: x
44 integer impure
function notpure(n
)
49 pure
real function f01(a
)
50 real, intent(in
) :: a
! ok
52 pure
real function f02(a
)
55 pure
real function f03(a
) ! C1583
56 !ERROR: non-POINTER dummy argument of pure function must be INTENT(IN) or VALUE
59 pure
real function f03a(a
)
60 real, pointer :: a
! ok
62 pure
real function f04(a
) ! C1583
63 !ERROR: non-POINTER dummy argument of pure function must be INTENT(IN) or VALUE
64 real, intent(out
) :: a
66 pure
real function f04a(a
)
67 real, pointer, intent(out
) :: a
! ok if pointer
69 pure
real function f05(a
) ! C1583
70 real, value
:: a
! weird, but ok (VALUE without INTENT)
72 pure
function f06() ! C1584
73 !ERROR: Result of pure function may not have an impure FINAL subroutine
74 type(impureFinal
) :: f06
76 pure
function f07() ! C1585
77 !ERROR: Result of pure function may not be both polymorphic and ALLOCATABLE
78 class(t
), allocatable
:: f07
80 pure
function f08() ! C1585
81 !ERROR: Result of pure function may not have polymorphic ALLOCATABLE ultimate component '%a'
82 type(polyAlloc
) :: f08
85 pure
subroutine s01(a
) ! C1586
86 !ERROR: non-POINTER dummy argument of pure subroutine must have INTENT() or VALUE attribute
89 pure
subroutine s01a(a
)
92 pure
subroutine s02(a
) ! C1587
93 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not have an impure FINAL subroutine
94 type(impureFinal
), intent(out
) :: a
96 pure
subroutine s03(a
) ! C1588
97 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not be polymorphic
98 class(t
), intent(out
) :: a
100 pure
subroutine s04(a
) ! C1588
101 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not have a polymorphic ultimate component
102 type(polyAlloc
), intent(out
) :: a
104 pure
subroutine s05
! C1589
105 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
107 !ERROR: A pure subprogram may not initialize a variable
109 !ERROR: A pure subprogram may not initialize a variable
112 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
117 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
119 !ERROR: A pure subprogram may not initialize a variable
123 pure
subroutine s06
! C1589
124 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
127 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
131 pure
subroutine s07(p
) ! C1590
132 !ERROR: A dummy procedure of a pure subprogram must be pure
133 procedure(impure
) :: p
135 ! C1591 is tested in call11.f90.
136 pure
subroutine s08
! C1592
138 pure
subroutine pure
! ok
140 !ERROR: An internal subprogram of a pure subprogram must also be pure
143 !ERROR: An internal subprogram of a pure subprogram must also be pure
144 impure
subroutine impure2
147 pure
subroutine s09
! C1593
149 !ERROR: VOLATILE variable 'volatile' may not be referenced in pure subprogram 's09'
152 ! C1594 is tested in call12.f90.
153 pure
subroutine s10
! C1595
155 !ERROR: Procedure 'notpure' referenced in pure subprogram 's10' must be pure too
158 pure
subroutine s11(to) ! C1596
159 ! Implicit deallocation at the end of the subroutine
160 !ERROR: Deallocation of polymorphic object 'auto%a' is not permitted in a pure subprogram
161 type(polyAlloc
) :: auto
162 type(polyAlloc
), intent(in out
) :: to
163 !ERROR: Left-hand side of assignment is not definable
164 !BECAUSE: 'to' has polymorphic non-coarray component '%a' in a pure subprogram
168 character(20) :: buff
170 write(buff
, *) 1.0 ! ok
172 !ERROR: External I/O is not allowed in a pure subprogram
173 print *, 'hi' ! C1597
174 !ERROR: External I/O is not allowed in a pure subprogram
175 open(1, file
='launch-codes') ! C1597
176 !ERROR: External I/O is not allowed in a pure subprogram
178 !ERROR: External I/O is not allowed in a pure subprogram
180 !Also checks parsing of variant END FILE spelling
181 !ERROR: External I/O is not allowed in a pure subprogram
183 !ERROR: External I/O is not allowed in a pure subprogram
185 !ERROR: External I/O is not allowed in a pure subprogram
187 !ERROR: External I/O is not allowed in a pure subprogram
189 !ERROR: External I/O is not allowed in a pure subprogram
190 inquire(1, name
=buff
) ! C1597
191 !ERROR: External I/O is not allowed in a pure subprogram
193 !ERROR: External I/O is not allowed in a pure subprogram
195 !ERROR: External I/O is not allowed in a pure subprogram
197 !ERROR: External I/O is not allowed in a pure subprogram
201 !ERROR: An image control statement may not appear in a pure subprogram
205 integer :: img
, nimgs
, i
[*], tmp
209 i
= img
! i is ready to use
211 if ( img
.eq
. 1 ) then
212 !ERROR: An image control statement may not appear in a pure subprogram
213 sync
images( nimgs
) ! explicit sync 1 with last img
215 !ERROR: An image control statement may not appear in a pure subprogram
216 sync
images( nimgs
) ! explicit sync 2 with last img
220 if ( img
.eq
. nimgs
) then
221 !ERROR: An image control statement may not appear in a pure subprogram
222 sync
images( 1 ) ! explicit sync 1 with img 1
224 !ERROR: An image control statement may not appear in a pure subprogram
225 sync
images( 1 ) ! explicit sync 2 with img 1
228 !ERROR: External I/O is not allowed in a pure subprogram
230 ! all other images wait here
231 ! TODO others from 11.6.1 (many)