Does a generic interface shadow a dangling procedure with the same name?

See the code below. It has 2 dangling routines foo() and foo_1(). In the program, an explicit interface is defined for foo_1(), and then foo_1() is listed under generic interface foo. That is, the generic interface foo has the same name as the dangling routine foo().

In all compilers I have tested (gfortran, ifx, nvfortran, flang, lfortran) the behavior is:

  • no name conflict at compilation
  • the generic interface “shadows” the dangling routine; that is, the program always prints "foo_1"
    Compiler Explorer

I guess then this is guaranteed by the standard (all the more than even with all warnings enabled, the compilers do not complain)… But it’s only a guess. Any comment?

subroutine foo()
    print*, "foo"
end subroutine

subroutine foo_1()
    print*, "foo_1"
end subroutine

program bar

    interface
        subroutine foo_1()
        end subroutine
    end interface

    interface foo
        procedure foo_1
    end interface

    call foo()

end

It’s invalid to refer to a generic identifier if it does not have a specific procedure with an interface compatible with the reference. So, in the example, the call must be referring to the only specific procedure with that generic identifier, that being foo_1.

Thus the answer to the question is yes, a generic identifier makes it impossible to call an external procedure with the same name via an implicit interface.

1 Like

That’s fine, this is the behavior I really want.

Not impossible but inconvenient. You can still call the external foo like this if you really need to:

    block
        external foo
        call foo()
    end block
1 Like