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
23 type(impureFinal
) :: x
25 integer impure
function notpure(n
)
30 pure
real function f01(a
)
31 real, intent(in
) :: a
! ok
33 pure
real function f02(a
)
36 pure
real function f03(a
) ! C1583
37 !ERROR: non-POINTER dummy argument of pure function must be INTENT(IN) or VALUE
40 pure
real function f03a(a
)
41 real, pointer :: a
! ok
43 pure
real function f04(a
) ! C1583
44 !ERROR: non-POINTER dummy argument of pure function must be INTENT(IN) or VALUE
45 real, intent(out
) :: a
47 pure
real function f04a(a
)
48 real, pointer, intent(out
) :: a
! ok if pointer
50 pure
real function f05(a
) ! C1583
51 real, value
:: a
! weird, but ok (VALUE without INTENT)
53 pure
function f06() ! C1584
54 !ERROR: Result of pure function may not have an impure FINAL subroutine
55 type(impureFinal
) :: f06
57 pure
function f07() ! C1585
58 !ERROR: Result of pure function may not be both polymorphic and ALLOCATABLE
59 class(t
), allocatable
:: f07
61 pure
function f08() ! C1585
62 !ERROR: Result of pure function may not have polymorphic ALLOCATABLE ultimate component '%a'
63 type(polyAlloc
) :: f08
66 pure
subroutine s01(a
) ! C1586
67 !ERROR: non-POINTER dummy argument of pure subroutine must have INTENT() or VALUE attribute
70 pure
subroutine s01a(a
)
73 pure
subroutine s02(a
) ! C1587
74 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not have an impure FINAL subroutine
75 type(impureFinal
), intent(out
) :: a
77 pure
subroutine s03(a
) ! C1588
78 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not be polymorphic
79 class(t
), intent(out
) :: a
81 pure
subroutine s04(a
) ! C1588
82 !ERROR: An INTENT(OUT) dummy argument of a pure subroutine may not have a polymorphic ultimate component
83 type(polyAlloc
), intent(out
) :: a
85 pure
subroutine s05
! C1589
86 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
88 !ERROR: A pure subprogram may not initialize a variable
90 !ERROR: A pure subprogram may not initialize a variable
93 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
98 !ERROR: A pure subprogram may not have a variable with the SAVE attribute
100 !ERROR: A pure subprogram may not initialize a variable
104 pure
subroutine s06
! C1589
105 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
108 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute
112 pure
subroutine s07(p
) ! C1590
113 !ERROR: A dummy procedure of a pure subprogram must be pure
114 procedure(impure
) :: p
116 ! C1591 is tested in call11.f90.
117 pure
subroutine s08
! C1592
119 pure
subroutine pure
! ok
121 !ERROR: An internal subprogram of a pure subprogram must also be pure
124 !ERROR: An internal subprogram of a pure subprogram must also be pure
125 impure
subroutine impure2
128 pure
subroutine s09
! C1593
130 !ERROR: VOLATILE variable 'volatile' may not be referenced in pure subprogram 's09'
133 ! C1594 is tested in call12.f90.
134 pure
subroutine s10
! C1595
136 !ERROR: Procedure 'notpure' referenced in pure subprogram 's10' must be pure too
139 pure
subroutine s11(to) ! C1596
140 ! Implicit deallocation at the end of the subroutine
141 !ERROR: Deallocation of polymorphic object 'auto%a' is not permitted in a pure subprogram
142 type(polyAlloc
) :: auto
143 type(polyAlloc
), intent(in out
) :: to
144 !ERROR: Deallocation of polymorphic non-coarray component '%a' is not permitted in a pure subprogram
148 character(20) :: buff
150 write(buff
, *) 1.0 ! ok
152 !ERROR: External I/O is not allowed in a pure subprogram
153 print *, 'hi' ! C1597
154 !ERROR: External I/O is not allowed in a pure subprogram
155 open(1, file
='launch-codes') ! C1597
156 !ERROR: External I/O is not allowed in a pure subprogram
158 !ERROR: External I/O is not allowed in a pure subprogram
160 !Also checks parsing of variant END FILE spelling
161 !ERROR: External I/O is not allowed in a pure subprogram
163 !ERROR: External I/O is not allowed in a pure subprogram
165 !ERROR: External I/O is not allowed in a pure subprogram
167 !ERROR: External I/O is not allowed in a pure subprogram
169 !ERROR: External I/O is not allowed in a pure subprogram
170 inquire(1, name
=buff
) ! C1597
171 !ERROR: External I/O is not allowed in a pure subprogram
173 !ERROR: External I/O is not allowed in a pure subprogram
175 !ERROR: External I/O is not allowed in a pure subprogram
177 !ERROR: External I/O is not allowed in a pure subprogram
181 !ERROR: An image control statement may not appear in a pure subprogram
185 integer :: img
, nimgs
, i
[*], tmp
189 i
= img
! i is ready to use
191 if ( img
.eq
. 1 ) then
192 !ERROR: An image control statement may not appear in a pure subprogram
193 sync
images( nimgs
) ! explicit sync 1 with last img
195 !ERROR: An image control statement may not appear in a pure subprogram
196 sync
images( nimgs
) ! explicit sync 2 with last img
200 if ( img
.eq
. nimgs
) then
201 !ERROR: An image control statement may not appear in a pure subprogram
202 sync
images( 1 ) ! explicit sync 1 with img 1
204 !ERROR: An image control statement may not appear in a pure subprogram
205 sync
images( 1 ) ! explicit sync 2 with img 1
208 !ERROR: External I/O is not allowed in a pure subprogram
210 ! all other images wait here
211 ! TODO others from 11.6.1 (many)