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

            Bug ID: 110629
           Summary: Bug in assignment of derived type with deferred length
                    character component
           Product: gcc
           Version: 12.2.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 with intrinsic assignment of derived types with
allocatable character components. This seems to be a resurgence of PR105205, in
that only the first element of the character array is copied correctly; the
rest is filled with garbage.

Here's a demo:

--
module m

   type :: bar_t
      character(:), allocatable :: c(:)
   end type bar_t

end module m


program p

   use m

   implicit none

   type(bar_t) :: bar
   type(bar_t) :: biz

   integer :: i

   allocate(character(10)::bar%c(3))

   bar%c(1) = 'big'
   bar%c(2) = 'red'
   bar%c(3) = 'dog'

   biz = bar

   do i = 1, 3
      print *, i, '|'//biz%c(i)//'|'
   end do

end program p
--

Output compiling with gfortran 12.2.0 on MacOS 13.4:

           1 |big       |
           2 |>|
           3 ||

Unfortunately, this may be a heisenbug -- some code where I do this kind of
assignment is affected, other code is not.

Reply via email to