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

            Bug ID: 125720
           Summary: Wrong code: structure constructor copies an
                    allocatable character array component at the wrong
                    element stride
           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]
  • [Bug fortran/125720] New: Wrong ... jvdelisle at gcc dot gnu.org via Gcc-bugs

Reply via email to