title: interfaced type-bound procedures in Fortran
body: <p>I am trying to define an <code>interface</code>d procedure as a type-bound procedure in a Fortran <code>type</code> definition, but it seems it doesn't work as one would expect. Consider the following module:</p>
  
  <pre><code>module example_module
  implicit none
  private
  
  interface add_them
    module procedure add_them_integer,add_them_real
  end interface add_them
  
  type, public :: foo
    integer, private :: a=1,b=2
    real, private :: c=4.,d=5.
  contains
    procedure, public :: add =&gt; add_them
  end type foo
  
  contains
  subroutine add_them_integer(self,x)
  class(foo), intent(in) :: self
  integer, intent(in) :: x
  print *,self%a+self%b+x
  end subroutine add_them_integer
  
  subroutine add_them_real(self,x)
  class(foo), intent(in) :: self
  real, intent(in) :: x
  print *,self%c+self%d+x
  end subroutine add_them_real
  end module example_module
  </code></pre>
  
  <p>and the corresponding program that uses the module:</p>
  
  <pre><code>program example
  use example_module
  implicit none
  type(foo) :: foofoo
  call foofoo%add(1)
  call foofoo%add(2.)
  end program example
  </code></pre>
  
  <p>I would expect this to compile and results should be 4 and 11. However, gfortran reports the following error:</p>
  
  <pre><code>procedure, public :: add =&gt; add_them
           1
  Error: 'add_them' must be a module procedure or an external procedure with an explicit interface at (1)
  </code></pre>
  
  <p>A workaround is to use <code>generic</code> type-bound procedure instead of an <code>interface</code>d one, so that the module is as follows:</p>
  
  <pre><code>module example_module
  implicit none
  private
  
  type, public :: foo
    integer, private :: a=1,b=2
    real, private :: c=4.,d=5.
  contains
    generic, public :: add =&gt; add_them_integer,add_them_real
    procedure, private :: add_them_integer,add_them_real
  end type foo
  
  contains
  subroutine add_them_integer(self,x)
  class(foo), intent(in) :: self
  integer, intent(in) :: x
  print *,self%a+self%b+x
  end subroutine add_them_integer
  
  subroutine add_them_real(self,x)
  class(foo), intent(in) :: self
  real, intent(in) :: x
  print *,self%c+self%d+x
  end subroutine add_them_real
  end module example_module
  </code></pre>
  
  <p>This works as expected. However, I cannot use a <code>generic</code> procedure. The above is just a simplified example to demonstrate the problem, but in my actual code 'add_them' cannot be a <code>generic</code> procedure because 'foo' is actually a derived-type and 'add_them' overrides a procedure defined in the parent type; gfortran (at least) does not allow <code>generic</code> procedures overriding base procedures. To bypass this restriction, I thought I should use an <code>interface</code> instead, but as you can see in the above example, although 'add_them' is defined correctly, compiler complains that "'add_them' must be a module procedure or an external procedure with an explicit interface".</p>
  
  <p>Any help would be appreciated; thanks in advance.</p>