Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

Expected behavior of type-bound operators

$
0
0

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


Viewing all articles
Browse latest Browse all 2746

Trending Articles



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