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

interface operator for extended derived-type

Ferdinand_T_
New Contributor II
542 Views

Hello,

in the example shown below I try to define a (non-type-bound*) operator for an extended derived-type "child". However, declaring the interface for the operator causes the Intel compiler to give me some errors which I do not understand. In some cases, the compiler even experiences a segmentation violation.

*) I didn't use type-bound operators, because I want to define operators between many different child - types, all of them extending one common 'super' - type, which at some point requires arguments (child - types) to appear in the type-bound operator function before they are declared.

[fortran]

module m

 
    ! superclass with type-bound generic
    type :: super
    contains
        procedure :: proc_specific
        generic :: proc_generic => proc_specific
    end type

 

    ! child inherits type-bound generic
    type, extends(super) :: child
    end type

 
    ! an arbitrary operator on the child, causes errors (see below)
    ! note: no errors caused if operator is declared for 'super' instead
    interface operator(.optr.)
        function multiply(arg1,arg2)
            import child
            implicit none
            type(child), intent(in) :: arg1, arg2
            type(child) :: multiply
        end function
    end interface

 
contains

 

    logical function proc_specific(this)
        implicit none
        class(super) :: this
    end function
end module

 


program p
    use m
    implicit none
    type(child) :: myChild


 
    print *, myChild%proc_specific()
    ! works fine

 

    print *, myChild%proc_generic()
    ! error #8485: There is no matching specific function for this
    !              type bound generic function reference.
    ! error #8497: Illegal use of a procedure name in an expression,
    !              possibly a function call missing parenthesis.

 
    ! call myChild%proc_generic()
    ! note: the use of a subroutine (proc_specific) instead of a function
    !       (deleting the return type) leads to a compiler segmentation
    !       violation as long as the operator is declared for 'child'
end program
[/fortran]

It seems to me that a generic operator interface for an extended derived-type somehow destroys all of it's type-bound inherited generic interfaces. Or am I finally making a mistake here? Is there an other way to define an operator for the 'child' (without dynamic 'select case')?

Any suggestions are appreciated!

Best regards, Ferdinand

0 Kudos
3 Replies
Steven_L_Intel1
Employee
542 Views

Thanks - I can reproduce both problems. Let me look into it a bit more and I'll get back to you. I don't think you're doing anything wrong.

0 Kudos
Steven_L_Intel1
Employee
542 Views

Escalated as issue DPD200241686. Thanks for the nice example.

0 Kudos
Steven_L_Intel1
Employee
542 Views
I expect this problem to be fixed in a release later this year.
0 Kudos
Reply