- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
[fortran]
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
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We're changing the compiler to make this a regular warning, not an error or standards warning, in a release later this year. The reason is that we actually depend on being able to mix functions and subroutines in some generic definitions in module IFPORT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perhaps you should consider adding a !DEC$ ... the permits you to avoid an error. If you omit the !DEC$... you get the error. IFPORT would be compiled with the appropriate !DEC$.
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page