Doubt w.r.t. to gfortran's interpretation of the Fortran2003 standard

Salvatore Filippone filippone.salvatore@gmail.com
Fri Oct 31 09:15:00 GMT 2014


Alberto F. Martín Huertas wrote:

>Dear Fortran@gcc.gnu.org members,
>
>I would like to know if the following Fortran2003 code snippet is compliant or not
>
>with the Fortran2003 standard:
>
>module overwrite
 > type madre
 > contains
 >  procedure :: sum => sum_madres
 >    generic   :: operator(+) => sum
 > end type madre
>
>  type, extends(madre) ::  hijo
>contains
>  procedure :: sum => sum_hijos_compliant
>  generic   :: operator(+) => sum
>end type hijo

Your code is wrong (I've been through the same error a long time ago :)
The fix is: do NOT add the derived procedure to the generic. Once a
type-bound procedure is added to a GENERIC interface, all TBPs that
override it are accessible through the same generic. In other words,
you only need to comment out the second generic statement as in the
following:
module overwrite
  type madre
  contains
   procedure :: sum => sum_madres
     generic   :: operator(+) => sum
  end type madre

  type, extends(madre) ::  hijo
contains
  procedure :: sum => sum_hijos_compliant
   !   generic   :: operator(+) => sum  ! not needed.
end type hijo

Hope this helps
Salvatore Filippone



More information about the Fortran mailing list