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

            Bug ID: 95682
           Summary: Default assignment fails with allocatable array of
                    deferred-length strings
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.perini at gmail dot com
  Target Milestone: ---

Created attachment 48734
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48734&action=edit
Test program

The attached code below just copies a variable into another one using the
default derived type assignment: 

module m
      implicit none

      type, public :: t
              character(len=:), allocatable :: x(:)
      end type t

end module m

program test
   use m
   integer :: i
   type(t) :: t1,t2

   allocate(character(len=20) :: t1%x(3))
   t1%x(1) = 'one'
   t1%x(2) = 'two'
   t1%x(3) = 'three'

   t2 = t1

   do i=1,3
      if (t1%x(i)==t2%x(i)) cycle
      print *, 'i=',i,' t1=',t1%x(i),' t2=',t2%x(i),' DO NOT MATCH! '
   end do

end program test

It should produce no output as the two variables have to be identical. However,
apparently values in the character array are only copied correctly from the
first element in the array. 

Output with gfortran 9.2.0 is:

$ a.exe
 i=           2  t1=two                  t2=    ─ó0╖++  └w≈      DO NOT MATCH!
 i=           3  t1=three                t2=                     DO NOT MATCH!

Thanks,

Federico

Reply via email to