3 ! Tests implementation of F2008 feature: pointer function assignments.
5 ! Contributed by Paul Thomas <pault@gcc.gnu.org>
9 function bar (arg, idx) result (res)
10 integer, pointer :: res
11 integer, target :: arg(:)
20 integer, allocatable, dimension (:) :: i
22 procedure, pass :: create
23 procedure, pass :: delete
24 procedure, pass :: fill
25 procedure, pass :: elem_fill
28 subroutine create (this, sz)
31 if (allocated (this%i)) deallocate (this%i)
35 subroutine delete (this)
37 if (allocated (this%i)) deallocate (this%i)
39 function fill (this, idx) result (res)
40 integer, pointer :: res(:)
42 class(mydt), target :: this
45 ub = lb + size(this%i) - 1
48 function elem_fill (this, idx) result (res)
49 integer, pointer :: res
50 class(mydt), target :: this
58 integer, target :: a(3) = [1,2,3]
60 integer :: foobar, z, i, ifill(4) = [2, 7, 19, 61], ifill2(2) = [1,2]
62 foobar (z) = z**2 ! { dg-warning "Obsolescent feature: Statement function" }
63 if (any (a .ne. [1,2,3])) STOP 1
65 ! Assignment to pointer result is after procedure call.
68 ! Assignment within procedure applies.
72 ! Use of index for assignment.
74 if (any (a .ne. [99,99,3])) STOP 3
76 ! Make sure that statement function still works!
77 if (foobar (10) .ne. 100) STOP 4
79 bar (a, 3) = foobar (9)
80 if (any (a .ne. [99,99,81])) STOP 5
82 ! Try typebound procedure
85 if (dt%i(3) .ne. 42) STOP 6
86 dt%elem_fill (3) = 42 + dt%elem_fill (3) ! PR63921 style assignment
87 if (dt%i(3) .ne. 84) STOP 7
88 dt%elem_fill (3) = dt%elem_fill (3) - dt%elem_fill (3)
89 if (dt%i(3) .ne. 0) STOP 8
91 dt%fill (3) = ifill ! Check with array variable rhs
92 dt%fill (1) = [2,1] ! Check with array constructor rhs
93 if (any (dt%i .ne. [2,1,ifill])) STOP 9
94 dt%fill (1) = footoo (size (dt%i, 1)) ! Check with array function rhs
95 if (any (dt%i .ne. [6,5,4,3,2,1])) STOP 10
96 dt%fill (3) = ifill + dt%fill (3) ! Array version of PR63921 assignment
97 if (any (dt%i .ne. [6,5,6,10,21,62])) STOP 11
102 integer, pointer :: foo
103 integer, target :: arg(:)
107 function footoo (arg) result(res)
110 res = [(arg - i, i = 0, arg - 1)]