Bug 58620 - [OOP] Defined assignment not called for TYPE when the type's extension is used
Summary: [OOP] Defined assignment not called for TYPE when the type's extension is used
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Reported: 2013-10-04 16:34 UTC by Tobias Burnus
Modified: 2014-03-22 15:27 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-22 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2013-10-04 16:34:09 UTC
Follow up to PR58469

The code below prints "42" as the defined assignment "assign0" isn't called for "foo". If one uses "type(component)" instead of "type(comp0)" for "foo", one gets the expected output: "20".

See also https://groups.google.com/forum/#!topic/comp.lang.fortran/6cW1K0Zj1gU

pgf95 and ifort ICEs for the code; using crayftn one gets the same result as with gfortran - namely "20".

module m0
  implicit none
  type :: component
    integer :: i = 42
    procedure :: assign0
    generic :: assignment(=) => assign0
  end type
  type, extends(component) :: comp2
    real :: aa
  end type comp2
  type parent
    type(comp2) :: foo
  end type
  elemental subroutine assign0(lhs,rhs)
    class(component), intent(INout) :: lhs
    class(component), intent(in) :: rhs
    lhs%i = 20
  end subroutine
end module

program main
  use m0
  implicit none
  type(parent), allocatable :: left
  type(parent) :: right
  left = right
  print *, left%foo
  if (left%foo%i /= 20) call abort()
Comment 1 Dominique d'Humieres 2014-03-22 15:27:48 UTC
Still present at r208765.