aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/pointer_check_15.f90
blob: 13c6820be0e32ac6dbcfa0aa94b6becd0ded94f6 (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
! { dg-do run }
! { dg-additional-options "-O -fcheck=pointer -fdump-tree-original" }
!
! PR fortran/121145
! Erroneous runtime error: Proc-pointer actual argument 'ptr' is not associated
!
! Contributed by Federico Perini.

module m
  implicit none

  abstract interface
     subroutine fun(x)
       real, intent(in) :: x
     end subroutine fun
  end interface   

contains

  subroutine with_fun(sub)
    procedure(fun), optional :: sub
    if (present(sub)) stop 1
  end subroutine   

  subroutine with_non_optional(sub)
    procedure(fun) :: sub
  end subroutine   

end module m

program p
  use m
  implicit none

  procedure(fun), pointer :: ptr1 => null()
  procedure(fun), pointer :: ptr2 => null()
  
  call with_fun()
  call with_fun(sub=ptr1)               ! no runtime check here

  if (associated (ptr2)) then
     call with_non_optional(sub=ptr2)   ! runtime check here
  end if
end  

! { dg-final { scan-tree-dump-times "Proc-pointer actual argument .'ptr2.'" 1 "original" } }