Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

Ifort bug: Loosing polymorphic information for overriden operators

$
0
0

Dear Intel developer,

The ifort 16 compiler (16.0.0 20150815) seems to generate non-standard conforming code, when a polymorphic type with an overriden operator is stored as a pointer within a derived type. The self containing example below demonstrates the issue for the comparison operator: the code calls the comparison operator of the basetype, instead of the extended one. Similar error happens if the assignment operator is overriden, so I guess, the problem is operator independent.

Best regards,

Bállint

module typedefs
  implicit none

  type :: Base
  contains
    procedure :: isEqualTo => Base_isEqualTo
    generic :: operator(==) => isEqualTo
  end type Base

  type, extends(Base) :: Extended
    integer :: data
  contains
    procedure :: isEqualTo => Extended_isEqualTo
  end type Extended

contains

  function Base_isEqualTo(this, other) result(isEqual)
    class(Base), intent(in) :: this
    class(Base), intent(in) :: other
    logical :: isEqual

    select type (other)
    type is (Base)
      isEqual = .true.
    class default
      isEqual = .false.
    end select
    print *, "Base_isEqualTo:", isEqual

  end function Base_isEqualTo


  function Extended_isEqualTo(this, other) result(isEqual)
    class(Extended), intent(in) :: this
    class(Base), intent(in) :: other
    logical :: isEqual

    select type (other)
    type is (Extended)
      isEqual = (this%data == other%data)
    class default
      isEqual = .false.
    end select
    print *, "Extended_isEqualTo:", isEqual

  end function Extended_isEqualTo

end module typedefs


program test
  use typedefs
  implicit none

  type :: BasePtr
    class(Base), pointer :: ptr
  end type BasePtr

  type(Extended) :: myExt1, myExt2
  logical :: isEqual
  type(BasePtr), allocatable :: array(:)

  myExt1%data = 1
  myExt2%data = 1
  allocate(array(2))
  allocate(array(1)%ptr, source=myExt1)
  allocate(array(2)%ptr, source=myExt2)
  ! This should invoke Extended_isEqualTo, but it calls Base_isEqualTo instead
  isEqual = (array(1)%ptr == array(2)%ptr)
  print *, "Main:", isEqual

end program test

 


Viewing all articles
Browse latest Browse all 3108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>