Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28759 Discussions

Generic type-bound operators in ifort

Kube__Ralph
Beginner
1,326 Views
Hello,
I am starting to work on an object oriented model in fortran.
Right now I am having a hard time defining a generic type-bound procedure in a module that I plan using as an operator.
The example code I am working with is in listing 3 in the appendix in http://portal.acm.org/citation.cfm?id=1644001.1644004,
but the following example code shows the problem as well:

MODULE m
IMPLICIT NONE

TYPE :: t
INTEGER :: i
CONTAINS
PROCEDURE :: assign_t_from_int
PROCEDURE :: equals_t_int
GENERIC :: ASSIGNMENT(=) => assign_t_from_int
GENERIC :: OPERATOR(==) => equals_t_int
END TYPE t

CONTAINS

SUBROUTINE assign_t_from_int (me, i)
IMPLICIT NONE
TYPE(t), INTENT(OUT) :: me
INTEGER, INTENT(IN) :: i
me = t (i)
END SUBROUTINE assign_t_from_int

LOGICAL FUNCTION equals_t_int (me, i)
IMPLICIT NONE
TYPE(t) :: me
INTEGER :: i
equals_t_int = (me%i == i)
END FUNCTION equals_t_int

END MODULE m

When I complie this with ifort I get the following error messages:


rku000@pallas:~/source/design_patterns/test$ ifort -c test2.f90
test2.f90(9): error #5082: Syntax error, found '::' when expecting one of: ( % : . = =>
GENERIC :: ASSIGNMENT(=) => assign_t_from_int
------------^
test2.f90(9): error #5082: Syntax error, found '=>' when expecting one of: , ;
GENERIC :: ASSIGNMENT(=) => assign_t_from_int
-----------------------------^
test2.f90(10): error #5082: Syntax error, found '::' when expecting one of: ( % : . = =>
GENERIC :: OPERATOR(==) => equals_t_int
------------^
test2.f90(10): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
GENERIC :: OPERATOR(==) => equals_t_int
-------------------------------------------^
test2.f90(15): error #8264: The passed-object dummy argument must be a polymorphic dummy data object if the type being defined is extensible. [ME]
SUBROUTINE assign_t_from_int (me, i)
--------------------------------^
test2.f90(22): error #8264: The passed-object dummy argument must be a polymorphic dummy data object if the type being defined is extensible. [ME]
LOGICAL FUNCTION equals_t_int (me, i)
---------------------------------^
compilation aborted for test2.f90 (code 1)

I do not understand why I get a syntax error here, the syntax looks compatible to the generic syntax definition in the "F95/2003 explained" book from Metcalf.
Does anybody have an idea?
0 Kudos
4 Replies
TimP
Honored Contributor III
1,326 Views
I haven't undertaken trial of various compiler versions to try to match your messages. 2 recent versions give me:

rk.f90(15): error #8264: The passed-object dummy argument must be a polymorphic
dummy data object if the type being defined is extensible. [ME]
SUBROUTINE assign_t_from_int (me, i)
--------------------------------------^
rk.f90(22): error #8264: The passed-object dummy argument must be a polymorphic
dummy data object if the type being defined is extensible. [ME]
LOGICAL FUNCTION equals_t_int (me, i)
---------------------------------------^
rk.f90(15): error #8420: If generic-spec is OPERATOR or ASSIGNMENT, each of its
specific bindings must have a passed object dummy argument. [ASSIGN_T_FROM_INT
]
SUBROUTINE assign_t_from_int (me, i)
-------------------^
rk.f90(22): error #8420: If generic-spec is OPERATOR or ASSIGNMENT, each of its
specific bindings must have a passed object dummy argument. [EQUALS_T_INT]
LOGICAL FUNCTION equals_t_int (me, i)
-------------------------^
rk.f90(22): error #8448: An explicit INTENT(IN) declaration is expected for this
dummy argument of a specific procedure in an OPERATOR generic binding. [ME]
LOGICAL FUNCTION equals_t_int (me, i)
---------------------------------------^
rk.f90(22): error #8448: An explicit INTENT(IN) declaration is expected for this
dummy argument of a specific procedure in an OPERATOR generic binding.
LOGICAL FUNCTION equals_t_int (me, i)

As far as I can see, these are associated with discrepancies between your example and MR&C. From Steve Lionel's comments on the forum, I've had the impression a new ifort version should appear within a month.
0 Kudos
Steven_L_Intel1
Employee
1,326 Views
Version 11.1 does not support GENERIC type-bound procedures. The next version, available soon, will. I have not yet tried your source in the new version to see what other issues there may be - I will try to get to that later today.
0 Kudos
Steven_L_Intel1
Employee
1,326 Views
The following compiles ok in the new version. I've modified the code to meet what I think the standard requires. Clearly the defined assignment procedure might need more inside the SELECT TYPE.

[fortran]MODULE m
  IMPLICIT NONE

  TYPE :: t
    INTEGER :: i
  CONTAINS
    PROCEDURE :: assign_t_from_int
    PROCEDURE :: equals_t_int
    GENERIC :: ASSIGNMENT(=) => assign_t_from_int
    GENERIC :: OPERATOR(==) => equals_t_int
  END TYPE t

CONTAINS

  SUBROUTINE assign_t_from_int (me, i)
    IMPLICIT NONE
    CLASS(t), INTENT(INOUT) :: me
    INTEGER, INTENT(IN) :: i
    SELECT TYPE (me)
    TYPE IS (T)
    me = t (i)
    END SELECT
  END SUBROUTINE assign_t_from_int

  LOGICAL FUNCTION equals_t_int (me, i)
    IMPLICIT NONE
    CLASS(t), INTENT(IN) :: me
    INTEGER, INTENT(IN) :: i
    equals_t_int = (me%i == i)
  END FUNCTION equals_t_int

END MODULE m[/fortran]
0 Kudos
Kube__Ralph
Beginner
1,326 Views

Thanks for the quick solution. I am really looking forward to see the new version of ifort and see how the new OO features are working then.

Cheers, Ralph

0 Kudos
Reply