aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/proc_ptr_comp_2.f90
blob: 33e32aaf63e2282e52353dfe524dbf4b126ea6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
! { dg-do run }
!
! PR39630: Fortran 2003: Procedure pointer components.
!
! Basic test for PPCs with FUNCTION interface and NOPASS.
!
! Contributed by Janus Weil <janus@gcc.gnu.org>

  type t
    procedure(fcn), pointer, nopass :: ppc
    procedure(abstr), pointer, nopass :: ppc1
    integer :: i
  end type

  abstract interface
    integer function abstr(x)
      integer, intent(in) :: x
    end function
  end interface

  type(t) :: obj
  procedure(fcn), pointer :: f
  integer :: base

  intrinsic :: iabs

! Check with interface from contained function
  obj%ppc => fcn
  base=obj%ppc(2)
  if (base/=4) call abort
  call foo (obj%ppc,3)

! Check with abstract interface
  obj%ppc1 => obj%ppc
  base=obj%ppc1(4)
  if (base/=8) call abort
  call foo (obj%ppc1,5)

! Check compatibility components with non-components  
  f => obj%ppc
  base=f(6)
  if (base/=12) call abort
  call foo (f,7)

contains

  integer function fcn(x)
    integer, intent(in) :: x
    fcn = 2 * x
  end function

  subroutine foo (arg, i)
    procedure (fcn), pointer :: arg
    integer :: i
    if (arg(i)/=2*i) call abort
  end subroutine

end