2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gfortran.dg / proc_ptr_result_3.f90
blob6e2e5244e9198777d471342889b671c97bbebae1
1 !{ dg-do run }
3 ! PR 36704: Procedure pointer as function result
5 ! Original test case from James Van Buskirk.
7 ! Adapted by Janus Weil <janus@gcc.gnu.org>
9 module store_subroutine
10 implicit none
12 abstract interface
13 subroutine sub(i)
14 integer, intent(inout) :: i
15 end subroutine sub
16 end interface
18 procedure(sub), pointer, private :: psub => NULL()
20 contains
22 subroutine set_sub(x)
23 procedure(sub) x
24 psub => x
25 end subroutine set_sub
27 function get_sub()
28 procedure(sub), pointer :: get_sub
29 get_sub => psub
30 end function get_sub
32 end module store_subroutine
34 program test
35 use store_subroutine
36 implicit none
37 procedure(sub), pointer :: qsub
38 integer :: k = 1
40 call my_sub(k)
41 if (k/=3) call abort
42 qsub => get_sub()
43 call qsub(k)
44 if (k/=9) call abort
45 end program test
47 recursive subroutine my_sub(j)
48 use store_subroutine
49 implicit none
50 integer, intent(inout) :: j
51 j = j*3
52 call set_sub(my_sub)
53 end subroutine my_sub