1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
2 ! Error tests for structure constructors: C1594 violations
3 ! from assigning globally-visible data to POINTER components.
4 ! This test is structconst03.f90 with the type parameters removed.
7 real, target
:: usedfrom1
15 type(has_pointer1
), allocatable
:: link1
! don't loop during analysis
18 type(has_pointer1
) :: pnested
19 type(has_pointer2
), allocatable
:: link2
21 type, extends(has_pointer2
) :: has_pointer3
22 type(has_pointer3
), allocatable
:: link3
26 type(t1
), allocatable
:: link
29 type(has_pointer1
) :: hp1
30 type(t2
), allocatable
:: link
33 type(has_pointer2
) :: hp2
34 type(t3
), allocatable
:: link
37 type(has_pointer3
) :: hp3
38 type(t4
), allocatable
:: link
40 real, target
:: modulevar1
= 0.
41 type(has_pointer1
) :: modulevar2
= has_pointer1(modulevar1
)
42 type(has_pointer2
) :: modulevar3
= has_pointer2(has_pointer1(modulevar1
))
43 type(has_pointer3
) :: modulevar4
= has_pointer3(has_pointer1(modulevar1
))
47 pure
subroutine ps1(dummy1
, dummy2
, dummy3
, dummy4
)
48 real, target
:: local1
53 real, intent(in
), target
:: dummy1
54 real, intent(inout
), target
:: dummy2
55 real, pointer :: dummy3
56 real, intent(inout
), target
:: dummy4
[*]
57 real, target
:: commonvar1
58 common /cblock
/ commonvar1
60 !ERROR: Externally visible object 'usedfrom1' may not be associated with pointer component 'pt1' in a pure procedure
62 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'pt1' in a pure procedure
64 !ERROR: Externally visible object 'cblock' may not be associated with pointer component 'pt1' in a pure procedure
66 !ERROR: Externally visible object 'dummy1' may not be associated with pointer component 'pt1' in a pure procedure
70 ! TODO when semantics handles coindexing:
71 ! TODO !ERROR: Externally visible object may not be associated with a pointer in a pure procedure
72 ! TODO x1 = t1(dummy4[0])
74 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
75 x2
= t2(has_pointer1(modulevar1
))
76 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
77 x3
= t3(has_pointer2(has_pointer1(modulevar1
)))
78 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
79 x4
= t4(has_pointer3(has_pointer1(modulevar1
)))
80 !ERROR: The externally visible object 'modulevar2' may not be used in a pure procedure as the value for component 'hp1' which has the pointer component 'ptop'
82 !ERROR: The externally visible object 'modulevar3' may not be used in a pure procedure as the value for component 'hp2' which has the pointer component 'ptop'
84 !ERROR: The externally visible object 'modulevar4' may not be used in a pure procedure as the value for component 'hp3' which has the pointer component 'ptop'
87 pure
subroutine subr(dummy1a
, dummy2a
, dummy3a
, dummy4a
)
88 real, target
:: local1a
93 real, intent(in
), target
:: dummy1a
94 real, intent(inout
), target
:: dummy2a
95 real, pointer :: dummy3a
96 real, intent(inout
), target
:: dummy4a
[*]
98 !ERROR: Externally visible object 'usedfrom1' may not be associated with pointer component 'pt1' in a pure procedure
100 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'pt1' in a pure procedure
102 !ERROR: Externally visible object 'commonvar1' may not be associated with pointer component 'pt1' in a pure procedure
104 !ERROR: Externally visible object 'dummy1' may not be associated with pointer component 'pt1' in a pure procedure
106 !ERROR: Externally visible object 'dummy1a' may not be associated with pointer component 'pt1' in a pure procedure
111 ! TODO when semantics handles coindexing:
112 ! TODO !ERROR: Externally visible object may not be associated with a pointer in a pure procedure
113 ! TODO x1a = t1(dummy4a[0])
115 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
116 x2a
= t2(has_pointer1(modulevar1
))
117 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
118 x3a
= t3(has_pointer2(has_pointer1(modulevar1
)))
119 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure
120 x4a
= t4(has_pointer3(has_pointer1(modulevar1
)))
121 !ERROR: The externally visible object 'modulevar2' may not be used in a pure procedure as the value for component 'hp1' which has the pointer component 'ptop'
123 !ERROR: The externally visible object 'modulevar3' may not be used in a pure procedure as the value for component 'hp2' which has the pointer component 'ptop'
125 !ERROR: The externally visible object 'modulevar4' may not be used in a pure procedure as the value for component 'hp3' which has the pointer component 'ptop'
130 pure
integer function pf1(dummy3
)
131 real, pointer :: dummy3
133 !ERROR: Externally visible object 'dummy3' may not be associated with pointer component 'pt1' in a pure procedure
136 pure
subroutine subr(dummy3a
)
137 real, pointer :: dummy3a
139 !ERROR: Externally visible object 'dummy3' may not be associated with pointer component 'pt1' in a pure procedure
145 impure
real function ipf1(dummy1
, dummy2
, dummy3
, dummy4
)
146 real, target
:: local1
151 real, intent(in
), target
:: dummy1
152 real, intent(inout
), target
:: dummy2
153 real, pointer :: dummy3
154 real, intent(inout
), target
:: dummy4
[*]
155 real, target
:: commonvar1
156 common /cblock
/ commonvar1
162 !WARNING: Pointer target is not a definable variable
163 !BECAUSE: 'dummy1' is an INTENT(IN) dummy argument
167 ! TODO when semantics handles coindexing:
168 ! TODO x1 = t1(dummy4[0])
170 x2
= t2(has_pointer1(modulevar1
))
171 x3
= t3(has_pointer2(has_pointer1(modulevar1
)))
172 x4
= t4(has_pointer3(has_pointer1(modulevar1
)))