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

            Bug ID: 125722
           Summary: Wrong code: structure constructor copy of an
                    allocatable character array component
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

A structure constructor that copies an allocatable or deferred-length
character ARRAY expression into an explicit-length allocatable character array
component produces wrong data when the source element length differs from the
component's declared length.

Minimal reproducer:

  program p
    type t
       character(2), allocatable :: c(:)
    end type t
    type(t) :: x
    character(:), allocatable :: d(:)
    allocate (character(4) :: d(2))
    d = [ "abcd", "efgh" ]
    x = t (d)
    print *, "[", x%c(1), "][", x%c(2), "]"
  end program p

Observed:

  [ab][cd]

The second element is "cd" (characters 3-4 of the first source element)
instead of "ef".

Expected:

  [ab][ef]

Reply via email to