2 ! { dg-options -std=f2003 }
4 ! Is a copy of ptr_func_assign_1.f08 with checks for F2008 standard.
6 ! Contributed by Paul Thomas <pault@gcc.gnu.org>
10 function bar (arg, idx) result (res)
11 integer, pointer :: res
12 integer, target :: arg(:)
21 integer, allocatable, dimension (:) :: i
23 procedure, pass :: create
24 procedure, pass :: delete
25 procedure, pass :: fill
26 procedure, pass :: elem_fill
29 subroutine create (this, sz)
32 if (allocated (this%i)) deallocate (this%i)
36 subroutine delete (this)
38 if (allocated (this%i)) deallocate (this%i)
40 function fill (this, idx) result (res)
41 integer, pointer :: res(:)
43 class(mydt), target :: this
46 ub = lb + size(this%i) - 1
49 function elem_fill (this, idx) result (res)
50 integer, pointer :: res
51 class(mydt), target :: this
59 integer, target :: a(3) = [1,2,3]
61 integer :: foobar, z, i, ifill(4) = [2, 7, 19, 61], ifill2(2) = [1,2]
63 foobar (z) = z**2 ! { dg-warning "Obsolescent feature: Statement function" }
64 if (any (a .ne. [1,2,3])) STOP 1
66 ! Assignment to pointer result is after procedure call.
67 foo (a) = 77 ! { dg-error "Pointer procedure assignment" }
69 ! Assignment within procedure applies.
73 ! Use of index for assignment.
74 bar (a, 2) = 99 ! { dg-error "Pointer procedure assignment" }
75 if (any (a .ne. [99,99,3])) STOP 3
77 ! Make sure that statement function still works!
78 if (foobar (10) .ne. 100) STOP 4
80 bar (a, 3) = foobar (9)! { dg-error "Pointer procedure assignment" }
81 if (any (a .ne. [99,99,81])) STOP 5
83 ! Try typebound procedure
85 dt%elem_fill (3) = 42 ! { dg-error "Pointer procedure assignment" }
86 if (dt%i(3) .ne. 42) STOP 6
87 dt%elem_fill (3) = 42 + dt%elem_fill (3)! { dg-error "Pointer procedure assignment" }
88 if (dt%i(3) .ne. 84) STOP 7
89 dt%elem_fill (3) = dt%elem_fill (3) - dt%elem_fill (3)! { dg-error "Pointer procedure assignment" }
90 if (dt%i(3) .ne. 0) STOP 8
92 dt%fill (3) = ifill ! { dg-error "Pointer procedure assignment" }
93 dt%fill (1) = [2,1] ! { dg-error "Pointer procedure assignment" }
94 if (any (dt%i .ne. [2,1,ifill])) STOP 9
95 dt%fill (1) = footoo (size (dt%i, 1)) ! { dg-error "Pointer procedure assignment" }
96 if (any (dt%i .ne. [6,5,4,3,2,1])) STOP 10
97 dt%fill (3) = ifill + dt%fill (3) ! { dg-error "Pointer procedure assignment" }
98 if (any (dt%i .ne. [6,5,6,10,21,62])) STOP 11
103 integer, pointer :: foo
104 integer, target :: arg(:)
108 function footoo (arg) result(res)
111 res = [(arg - i, i = 0, arg - 1)]