2 ! Tests the fix for PR20863 and PR20882, which were concerned with incorrect
3 ! application of constraints associated with "impure" variables in PURE
6 ! resolve.c (gfc_impure_variable) detects the following:
7 ! 12.6 Constraint: In a pure subprogram any variable which is in common or
8 ! accessed by host or use association, is a dummy argument to a pure function,
9 ! is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
10 ! is storage associated with any such variable, shall not be used in the
11 ! following contexts: (clients of this function). */
13 ! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
17 TYPE(node_type
), POINTER :: next
=>null()
20 ! Original bug - pointer assignments to "impure" derived type with
22 PURE
FUNCTION give_next1(node
)
23 TYPE(node_type
), POINTER :: node
24 TYPE(node_type
), POINTER :: give_next
25 give_next
=> node
%next
! { dg-error "Bad target" }
26 node
%next
=> give_next
! { dg-error "variable definition context" }
29 PURE
integer FUNCTION give_next2(i
)
32 TYPE(node_type
), POINTER :: next
34 TYPE(node_type
), POINTER :: node
35 TYPE(node_type
), target
:: t
36 integer, intent(in
) :: i
37 node
%next
= t
! This is OK
40 PURE
FUNCTION give_next3(node
)
41 TYPE(node_type
), intent(in
) :: node
42 TYPE(node_type
) :: give_next
43 give_next
= node
! { dg-error "impure variable" }
51 TYPE(T1
), POINTER :: B
53 PURE
FUNCTION TST(A
) RESULT(RES
)
54 TYPE(T1
), INTENT(IN
), TARGET
:: A
55 TYPE(T1
), POINTER :: RES
56 RES
=> A
! { dg-error "Bad target" }
57 RES
=> B
! { dg-error "Bad target" }
58 B
=> RES
! { dg-error "variable definition context" }
60 PURE
FUNCTION TST2(A
) RESULT(RES
)
61 TYPE(T1
), INTENT(IN
), TARGET
:: A
62 TYPE(T1
), POINTER :: RES
65 B
= RES
! { dg-error "variable definition context" }