Error in generic binding with both functions and subroutines

Error in generic binding with both functions and subroutines

Ritratto di flying_hermes

Hi,

I've encountered what I believe is a bug in ifort version 14.0.0.

The problem occures when using a generic binding using both some functions and some subroutines.

A compilation error appears when a function is specified first in the generic binding declaration.

So, a simple workaround is to declare a subroutine first, then either functions or subroutines. The important point is that the first procedure to be declare must be a subroutine

Here a small example to reproduce the error.

Module Bug_Generic_Binding
  implicit none
  Type  ::      MyType
  contains
    generic     ::      MyProcedure => MySubroutine, MyFunction1, MyFunction2   ! THIS WORKS...
!     generic     ::      MyProcedure => MyFunction1, MyFunction2, MySubroutine ! THIS DON'T WORK => error #8447: A specific procedure must be a function for an OPERATOR generic binding.   [MYSUBROUTINE]
    procedure   ::      MySubroutine
    procedure   ::      MyFunction1
    procedure   ::      MyFunction2
  End Type
  contains
Pure Function MyFunction1( This, Inp1 ) result(Out1)
  class(MyType) ,intent(in)     ::      This
  real(8)       ,intent(in)     ::      Inp1
  real(8)                       ::      Out1
  Out1 = Inp1
End Function
Pure Function MyFunction2( This, Inp1, Inp2 ) result(Out1)
  class(MyType) ,intent(in)     ::      This
  real(8)       ,intent(in)     ::      Inp1
  real(8)       ,intent(in)     ::      Inp2
  real(8)                       ::      Out1
  Out1 = Inp1
End Function
Subroutine MySubroutine( This, Inp1, Out1, Out2)
  class(MyType) ,intent(in)     ::      This
  real(8)       ,intent(in)     ::      Inp1
  real(8)       ,intent(out)    ::      Out1
  real(8)       ,intent(out)    ::      Out2
  Out1 = Inp1
  Out2 = Inp1
End Subroutine
End Module

2 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Steve Lionel (Intel)
Best Reply

Actually, both are wrong. The Fortran standard requires that in a generic declaration, all procedures must be subroutines or all must be functions - you're not allowed to mix them.

C1215: Within the scope of a generic name, each pair of procedures identified by that name shall both be subroutines or both be functions (F2008 12.4.3.4.5p3)

So ifort is wrong in accepting the first case, and the error message is wrong (or at least confusing) in the second case.  I will report this to the developers. Issuer ID is DPD200247914.

As a second opinion, I tried gfortran and it said:

    generic     ::      MyProcedure => MySubroutine, MyFunction1, MyFunction2
                                      1
Error: 'mysubroutine' and 'myfunction2' can't be mixed FUNCTION/SUBROUTINE for GENERIC 'myprocedure' at (1)

Steve

Accedere per lasciare un commento.