1! { dg-do run }
2! { dg-options "-fcheck=recursion" }
3! { dg-shouldfail "Recursion check" }
4!
5! { dg-output "Fortran runtime error: Recursive call to nonrecursive procedure 'f'" }
6!
7! PR fortran/39577
8!
9! wrong - recursion
10program test
11 integer :: i
12 i = f(.false.)
13 print *,i
14 i = f(.true.)
15 print *,i
16contains
17  integer function f(rec)
18    logical :: rec
19    if(rec) then
20      f = g()
21    else
22      f = 42
23    end if
24  end function f
25  integer function g()
26    g = f(.false.)
27  end function g
28end program test
29