Skip to content

Flang does not look for locally scoped interfaces before module level interfaces with the same name #164303

@tarunprabhu

Description

@tarunprabhu

The code below compiles with gfortran, but fails to compile with flang.

module foo_mod
  use, intrinsic :: iso_fortran_env
  use, intrinsic :: iso_c_binding
  implicit none

  interface new_foo
    procedure :: foo_ctor
  end interface

contains

function foo_ctor(options) result(retval)
  implicit none
  integer, intent(in) :: options
  integer :: retval

  interface
    subroutine new_foo(f, opt) bind(c, name='new_foo')
      import
      implicit none
      integer, intent(inout) :: f
      integer(c_int), intent(in) :: opt
    end subroutine
  end interface

  call new_foo(retval, options)
end function

end module

With flang, the error that is raised is:

error: Cannot call function 'new_foo' like a subroutine
    call new_foo(retval, options)
         ^^^^^^^
foo.f90:14:13: Declaration of 'new_foo'
    interface new_foo
              ^^^^^^^

This code is derived from an application used within our organization. A more complete reproducer (containing a main function, the C++ codefor new_foo and a cmake script is attached).

flang_interface_scope_reproducer.tar.gz

MD5 for attachment: 6931ab65231672d1bc51ce39095243ae

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions