1! { dg-do compile }
2! Tests the fix for PR20880, which was due to failure to the failure
3! to detect the USE association of a nameless interface for a
4! procedure with the same name as the encompassing scope.
5!
6! Contributed by Joost VandeVondele  <jv244@cam.ac.uk>
7!
8! Modified for PR fortran/34657
9!
10module test_mod
11interface
12  subroutine my_sub (a)
13    real a
14  end subroutine
15end interface
16interface
17  function my_fun (a)
18    real a, my_fun
19  end function
20end interface
21end module
22
23module test_mod2
24interface
25  function my_fun (a)
26    real a, my_fun
27  end function
28end interface
29end module
30
31
32! This is the original PR, excepting that the error requires the symbol
33! to be referenced.
34subroutine my_sub (a)
35  use test_mod     ! { dg-error "is also the name of the current program unit" }
36  real a
37  call my_sub (a)  ! { dg-error "ambiguous reference" }
38  print *, a
39end subroutine
40
41integer function my_fun (a)
42  use test_mod ! { dg-error "is also the name of the current program unit" }
43  real a
44  print *, a
45  my_fun = 1  ! { dg-error "ambiguous reference" }
46end function
47
48! This was found whilst investigating => segfault
49subroutine thy_sub (a)
50  interface
51    subroutine thy_sub (a) ! { dg-error "enclosing procedure" }
52      real a
53    end subroutine
54  end interface
55  real a
56  print *, a
57end subroutine
58
59subroutine thy_fun (a)
60  use test_mod
61  use test_mod2  ! OK because there is no reference to my_fun
62  print *, a
63end subroutine thy_fun
64
65subroutine his_fun (a)
66  use test_mod
67  use test_mod2
68  print *, my_fun (a)  ! { dg-error "ambiguous reference" }
69end subroutine his_fun
70