https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98336

            Bug ID: 98336
           Summary: [OOP] CLASS assignment to derived-type component does
                    not use __copy/allocate
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

I tried the following:

  forall (i=1:5) f(i)%f = b

but looking at the dump, I see:
   f[i.0 + -1].f = VIEW_CONVERT_EXPR<struct __class_test_assign_Foo_t_a>(b);

EXPECTED: Memory allocation + __copy call.

Likewise with the DO loop.

(I started with this as I wondered whether I need to add a gfc_find_vtab call
to  gfc_resolve_assign_in_forall or not → PR fortran/92587.)


! { dg-do run }
!
! Cf. PR 86484:[OOP] Undefined symbol when using polymorphic intrinsic
assignment
! and PR fortran/92587
! 
program test_assign
  implicit none

  type :: foo_t
  end type
  type, extends (foo_t) :: bar_t
   integer :: j
  end type

  type t
     class(foo_t), allocatable :: f
  end type t
  type(t) :: f(5)
  type(bar_t)               :: b
  integer :: i
  b%j = 42 
! VARIANT 1
!  do i = 1, 5
!    f(i)%f = b
!  end do
! VARIANT 2
  forall (i=1:5) f(i)%f = b

  do i = 1, 5
    associate (x => f(i)%f)
      select type(x)
        type is (bar_t)
          if (x%j /= 42) stop 1
          x%j = 10*i
        class default
          stop 2
      end select
    end associate
  end do

  do i = 1, 5
    select type(x => f(i)%f)
      class is (bar_t)
        if (x%j /= 10*i) stop 3
      class default
        stop 4
    end select
  end do
end

Reply via email to