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

            Bug ID: 110877
           Summary: Incorrect copy of allocatable component in polymorphic
                    assignment from array dummy argument
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: townsend at astro dot wisc.edu
  Target Milestone: ---

I've run into a problem that's demonstrated by the following code:

--
module avs_m

   type :: foo_t
   end type foo_t

   type, extends(foo_t) :: bar_t
      real, allocatable :: a
   end type bar_t

end module avs_m

program assign_vs_source

   use avs_m

   implicit none

   class(foo_t), allocatable :: foo(:)

   allocate(bar_t::foo(1))
   select type(foo)
   class is (bar_t)
      allocate(foo(1)%a)
   end select

   call check_assign(foo)

contains

   subroutine check_assign(f)

      class(foo_t), intent(in)  :: f(:)
      class(foo_t), allocatable :: g(:)

      g = f

      select type(g)
      class is (bar_t)
         print *,'is allocated?', allocated(g(1)%a)
      end select

      deallocate(g)
      allocate(g, SOURCE=f)

      select type(g)
      class is (bar_t)
         print *,'is allocated?', allocated(g(1)%a)
      end select

   end subroutine check_assign

end program assign_vs_source
--

Expected output is 

 is allocated? T
 is allocated? T

but instead I get (gfortran 13.1.0, MacOS 13.4 x86_64):

 is allocated? F
 is allocated? T

It seems that the polymorphic assignment g=f is not correctly allocating the %a
component -- but the sourced allocation is. The problem seems to go away if (1)
I use scalars for foo, f and g, or (2) if I move the code from the check_assign
subroutine to the main program.

cheers,

Rich

Reply via email to