1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
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 !WARNING: non-POINTER dummy argument of pure function must have INTENT() or VALUE attribute
59 pure
real function f03a(a
)
60 real, pointer :: a
! ok
62 pure
real function f04(a
) ! C1583
63 !WARNING: non-POINTER dummy argument of pure function should 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 potential component '%a'
82 type(polyAlloc
) :: f08
85 pure
subroutine s01(a
) ! C1586
86 !WARNING: 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
115 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
117 !ERROR: A pure subprogram may not initialize a variable
121 pure
subroutine s06
! C1589
122 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
125 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
129 pure
subroutine s07(p
) ! C1590
130 !ERROR: A dummy procedure of a pure subprogram must be pure
131 procedure(impure
) :: p
133 ! C1591 is tested in call11.f90.
134 pure
subroutine s08
! C1592
136 pure
subroutine pure
! ok
138 !ERROR: An internal subprogram of a pure subprogram must also be pure
141 !ERROR: An internal subprogram of a pure subprogram must also be pure
142 impure
subroutine impure2
145 pure
subroutine s09
! C1593
147 !ERROR: VOLATILE variable 'volatile' may not be referenced in pure subprogram 's09'
150 ! C1594 is tested in call12.f90.
151 pure
subroutine s10
! C1595
153 !ERROR: Procedure 'notpure' referenced in pure subprogram 's10' must be pure too
156 pure
subroutine s11(to) ! C1596
157 ! Implicit deallocation at the end of the subroutine
158 !ERROR: 'auto' may not be a local variable in a pure subprogram
159 !BECAUSE: 'auto' has polymorphic component '%a' in a pure subprogram
160 type(polyAlloc
) :: auto
161 type(polyAlloc
), intent(in out
) :: to
162 !ERROR: Left-hand side of assignment is not definable
163 !BECAUSE: 'to' has polymorphic component '%a' in a pure subprogram
167 character(20) :: buff
169 write(buff
, *) 1.0 ! ok
171 !ERROR: External I/O is not allowed in a pure subprogram
172 print *, 'hi' ! C1597
173 !ERROR: External I/O is not allowed in a pure subprogram
174 open(1, file
='launch-codes') ! C1597
175 !ERROR: External I/O is not allowed in a pure subprogram
177 !ERROR: External I/O is not allowed in a pure subprogram
179 !Also checks parsing of variant END FILE spelling
180 !ERROR: External I/O is not allowed in a pure subprogram
182 !ERROR: External I/O is not allowed in a pure subprogram
184 !ERROR: External I/O is not allowed in a pure subprogram
186 !ERROR: External I/O is not allowed in a pure subprogram
188 !ERROR: External I/O is not allowed in a pure subprogram
189 inquire(1, name
=buff
) ! C1597
190 !ERROR: External I/O is not allowed in a pure subprogram
192 !ERROR: External I/O is not allowed in a pure subprogram
194 !ERROR: External I/O is not allowed in a pure subprogram
196 !ERROR: External I/O is not allowed in a pure subprogram
200 !ERROR: An image control statement may not appear in a pure subprogram
204 integer :: img
, nimgs
, i
[*], tmp
208 i
= img
! i is ready to use
210 if ( img
.eq
. 1 ) then
211 !ERROR: An image control statement may not appear in a pure subprogram
212 sync
images( nimgs
) ! explicit sync 1 with last img
214 !ERROR: An image control statement may not appear in a pure subprogram
215 sync
images( nimgs
) ! explicit sync 2 with last img
219 if ( img
.eq
. nimgs
) then
220 !ERROR: An image control statement may not appear in a pure subprogram
221 sync
images( 1 ) ! explicit sync 1 with img 1
223 !ERROR: An image control statement may not appear in a pure subprogram
224 sync
images( 1 ) ! explicit sync 2 with img 1
227 !ERROR: External I/O is not allowed in a pure subprogram
229 ! all other images wait here
230 ! TODO others from 11.6.1 (many)