Expected behavior of type-bound operators

Expected behavior of type-bound operators

Hi

If I compile the following code with ifort 14.0.3

module abmod
  implicit none

  type :: a
     integer :: value
   contains
     procedure :: assign => a_assign
     generic :: assignment(=) => assign
  end type a

  type, extends(a) :: b
   contains
     procedure :: assign => b_assign
  end type b

contains
  subroutine a_assign(this, value)
    implicit none
    class(a), intent(out) :: this
    integer, intent(in) :: value
    print *, "I am a_assign!"
    this%value=value
  end subroutine a_assign
    
  subroutine b_assign(this, value)
    implicit none
    class(b), intent(out) :: this
    integer, intent(in) :: value
    print *, "I am b_assign!"
    this%value=value
  end subroutine b_assign

end module abmod

program test
  use abmod
  implicit none

  class(a), allocatable :: aclass
  class(b), allocatable :: bclass

  allocate(b::aclass)
  allocate(bclass)

  aclass=1
  bclass=1
end program test

And run the program, I get

$ ifort -g -o test test.f90

$ ./test

I am a_assign!

I am a_assign!

$

Is this the expected behavior? I had expected that the b_assign procedure would have been called in both cases, due to the dynamic type being class b. I see similar behavior with the other operators.

If I use gfortran 4.6, 4.7 or 4.9, the b_assign procedure is called. However gfortran 4.8 shows similar behavior as ifort 14.0.3

Best regards

Emil Sørensen

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

This behavior from ifort doesn’t make sense to me, I would expect assign_b to be called as well. Haven’t had time to dig through the standard yet, however.

-Zaak

I also see the same reported behavior with our current Beta. I reported this to Development (see internal tracking id below) to get their assessment and will keep you updated on what I hear.

(Internal tracking id: DPD200358171)

Leave a Comment

Please sign in to add a comment. Not a member? Join today