PR c/29467
[official-gcc.git] / gcc / testsuite / gfortran.dg / proc_ptr_34.f90
blobfc5df1f298ea1b87aac0b91307e0b9e08d129a93
1 ! { dg-do compile }
3 ! PR fortran/52469
5 ! This was failing as the DECL of the proc pointer "func"
6 ! was used for the interface of the proc-pointer component "my_f_ptr"
7 ! rather than the decl of the proc-pointer target
9 ! Contributed by palott@gmail.com
12 module ExampleFuncs
13 implicit none
15 ! NOTE: "func" is a procedure pointer!
16 pointer :: func
17 interface
18 function func (z)
19 real :: func
20 real, intent (in) :: z
21 end function func
22 end interface
24 type Contains_f_ptr
25 procedure (func), pointer, nopass :: my_f_ptr
26 end type Contains_f_ptr
27 contains
29 function f1 (x)
30 real :: f1
31 real, intent (in) :: x
33 f1 = 2.0 * x
35 return
36 end function f1
38 function f2 (x)
39 real :: f2
40 real, intent (in) :: x
42 f2 = 3.0 * x**2
44 return
45 end function f2
47 function fancy (func, x)
48 real :: fancy
49 real, intent (in) :: x
51 interface AFunc
52 function func (y)
53 real :: func
54 real, intent (in) ::y
55 end function func
56 end interface AFunc
58 fancy = func (x) + 3.3 * x
59 end function fancy
61 end module ExampleFuncs
64 program test_proc_ptr
65 use ExampleFuncs
66 implicit none
68 type (Contains_f_ptr), dimension (2) :: NewType
70 !NewType(1) % my_f_ptr => f1
71 NewType(2) % my_f_ptr => f2
73 !write (*, *) NewType(1) % my_f_ptr (3.0), NewType(2) % my_f_ptr (3.0)
74 write (6, *) NewType(2) % my_f_ptr (3.0) ! < Shall print '27.0'
76 stop
77 end program test_proc_ptr