annotate gcc/testsuite/gfortran.dg/impure_assignment_2.f90 @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ! { dg-do compile }
kono
parents:
diff changeset
2 ! Tests the fix for PR20863 and PR20882, which were concerned with incorrect
kono
parents:
diff changeset
3 ! application of constraints associated with "impure" variables in PURE
kono
parents:
diff changeset
4 ! procedures.
kono
parents:
diff changeset
5 !
kono
parents:
diff changeset
6 ! resolve.c (gfc_impure_variable) detects the following:
kono
parents:
diff changeset
7 ! 12.6 Constraint: In a pure subprogram any variable which is in common or
kono
parents:
diff changeset
8 ! accessed by host or use association, is a dummy argument to a pure function,
kono
parents:
diff changeset
9 ! is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
kono
parents:
diff changeset
10 ! is storage associated with any such variable, shall not be used in the
kono
parents:
diff changeset
11 ! following contexts: (clients of this function). */
kono
parents:
diff changeset
12 !
kono
parents:
diff changeset
13 ! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
kono
parents:
diff changeset
14 !
kono
parents:
diff changeset
15 MODULE pr20863
kono
parents:
diff changeset
16 TYPE node_type
kono
parents:
diff changeset
17 TYPE(node_type), POINTER :: next=>null()
kono
parents:
diff changeset
18 END TYPE
kono
parents:
diff changeset
19 CONTAINS
kono
parents:
diff changeset
20 ! Original bug - pointer assignments to "impure" derived type with
kono
parents:
diff changeset
21 ! pointer component.
kono
parents:
diff changeset
22 PURE FUNCTION give_next1(node)
kono
parents:
diff changeset
23 TYPE(node_type), POINTER :: node
kono
parents:
diff changeset
24 TYPE(node_type), POINTER :: give_next
kono
parents:
diff changeset
25 give_next => node%next ! { dg-error "Bad target" }
kono
parents:
diff changeset
26 node%next => give_next ! { dg-error "variable definition context" }
kono
parents:
diff changeset
27 END FUNCTION
kono
parents:
diff changeset
28 ! Comment #2
kono
parents:
diff changeset
29 PURE integer FUNCTION give_next2(i)
kono
parents:
diff changeset
30 TYPE node_type
kono
parents:
diff changeset
31 sequence
kono
parents:
diff changeset
32 TYPE(node_type), POINTER :: next
kono
parents:
diff changeset
33 END TYPE
kono
parents:
diff changeset
34 TYPE(node_type), POINTER :: node
kono
parents:
diff changeset
35 TYPE(node_type), target :: t
kono
parents:
diff changeset
36 integer, intent(in) :: i
kono
parents:
diff changeset
37 node%next = t ! This is OK
kono
parents:
diff changeset
38 give_next2 = i
kono
parents:
diff changeset
39 END FUNCTION
kono
parents:
diff changeset
40 PURE FUNCTION give_next3(node)
kono
parents:
diff changeset
41 TYPE(node_type), intent(in) :: node
kono
parents:
diff changeset
42 TYPE(node_type) :: give_next
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
43 give_next = node ! { dg-error "pure subprogram" }
111
kono
parents:
diff changeset
44 END FUNCTION
kono
parents:
diff changeset
45 END MODULE pr20863
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 MODULE pr20882
kono
parents:
diff changeset
48 TYPE T1
kono
parents:
diff changeset
49 INTEGER :: I
kono
parents:
diff changeset
50 END TYPE T1
kono
parents:
diff changeset
51 TYPE(T1), POINTER :: B
kono
parents:
diff changeset
52 CONTAINS
kono
parents:
diff changeset
53 PURE FUNCTION TST(A) RESULT(RES)
kono
parents:
diff changeset
54 TYPE(T1), INTENT(IN), TARGET :: A
kono
parents:
diff changeset
55 TYPE(T1), POINTER :: RES
kono
parents:
diff changeset
56 RES => A ! { dg-error "Bad target" }
kono
parents:
diff changeset
57 RES => B ! { dg-error "Bad target" }
kono
parents:
diff changeset
58 B => RES ! { dg-error "variable definition context" }
kono
parents:
diff changeset
59 END FUNCTION
kono
parents:
diff changeset
60 PURE FUNCTION TST2(A) RESULT(RES)
kono
parents:
diff changeset
61 TYPE(T1), INTENT(IN), TARGET :: A
kono
parents:
diff changeset
62 TYPE(T1), POINTER :: RES
kono
parents:
diff changeset
63 allocate (RES)
kono
parents:
diff changeset
64 RES = A
kono
parents:
diff changeset
65 B = RES ! { dg-error "variable definition context" }
kono
parents:
diff changeset
66 RES = B
kono
parents:
diff changeset
67 END FUNCTION
kono
parents:
diff changeset
68 END MODULE pr20882