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

Type bound generic operator oddity

IanH
Honored Contributor III
416 Views
With 12.0.4 (and earlier) I'm getting some unexpected errors about user-defined type-bound operators.
[fortran]MODULE GenericUnaryOperatorModule
   IMPLICIT NONE

   TYPE, ABSTRACT :: Parent
     CHARACTER(:), ALLOCATABLE :: some_text
   CONTAINS
     PROCEDURE(parent_UnaryOp_abstract), DEFERRED :: UnaryOp
     GENERIC :: OPERATOR(.UnaryOp.) => UnaryOp
   END TYPE Parent

   ABSTRACT INTERFACE
     FUNCTION parent_UnaryOp_abstract(lhs) RESULT(res)
       IMPORT Parent
       IMPLICIT NONE
       CLASS(Parent), INTENT(IN) :: lhs
       CLASS(Parent), ALLOCATABLE :: res
     END FUNCTION parent_UnaryOp_abstract
   END INTERFACE

   TYPE, EXTENDS(Parent) :: Extension
   CONTAINS
     PROCEDURE :: UnaryOp => ext_UnaryOp
   END TYPE Extension
CONTAINS
   FUNCTION ext_UnaryOp(lhs) RESULT(res)
     CLASS(Extension), INTENT(IN) :: lhs
     CLASS(Parent), ALLOCATABLE:: res
     !****
     ALLOCATE(res, SOURCE=Extension('ext_UnaryOp'))
   END FUNCTION ext_UnaryOp

   SUBROUTINE dump(arg)
     CLASS(Parent), INTENT(IN) :: arg
     PRINT "(A)", arg%some_text
   END SUBROUTINE dump
END MODULE GenericUnaryOperatorModule

PROGRAM GenericUnaryOperator
   USE GenericUnaryOperatorModule
   IMPLICIT NONE
   CLASS(Parent), ALLOCATABLE :: a
   TYPE(Extension) :: b
   !****
   ALLOCATE(Extension:: a)
   CALL dump(.UnaryOp. a)
   
   ! Unexpected error #6764?
   CALL dump(.UnaryOp. b)     ! #1
END PROGRAM GenericUnaryOperator
[/fortran]
If you comment out #1 above to allow compilation to succeed you'll get a link time reference to the abstract interface (I think that's already reported?).

This is a follow on from a post on c.l.f recently (http://coding.derkeiler.com/Archive/Fortran/comp.lang.fortran/2011-05/msg00504.html) where I was blundering around trying to understand how these generics could be used. The code in that post shows some very wishful but erroneous thinking on my part and also the compiler failing to pick up on ambiguous interfaces for the generic.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
416 Views
Thanks - I have escalated this issue as DPD200169597.
0 Kudos
Steven_L_Intel1
Employee
416 Views
A fix for this has been found and will be in a release later this year. Sorry for the delay.
0 Kudos
Reply