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

            Bug ID: 72790
           Summary: MOVE_ALLOC() of character looses content data
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nathanael.huebbe at informatik dot uni-hamburg.de
  Target Milestone: ---

Created attachment 39052
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39052&action=edit
Code to reproduced the bug

The following code snippet reproduces the problem:

    program move_alloc_test
        character(:), allocatable :: srcString, destString
        integer, allocatable :: srcArray(:), destArray(:)

        srcString = "foo"
        call move_alloc(srcString, destString)
        write(0,*) "destString = '"//destString//"', &
                   &allocated(srcString) = ", allocated(srcString), ", &
                   &allocated(destString) = ", allocated(destString)

        srcArray = [1, 2, 3]
        call move_alloc(srcArray, destArray)
        write(0,*) "destArray = (", destArray, "), &
                   &allocated(srcArray) = ", allocated(srcArray), ", &
                   &allocated(destArray) = ", allocated(destArray)
    end program

The output of this program, when compiled with either gfortran 4.9.2 or 5.1.0,
shows an empty `destString` after the `move_alloc()` call:

     destString = '', allocated(srcString) =  F , allocated(destString) =  T
     destArray = (           1           2           3 ), allocated(srcArray) =
 F , allocated(destArray) =  T

The output that I would have expected is this:

     destString = 'foo', allocated(srcString) =  F , allocated(destString) =  T
     destArray = (           1           2           3 ), allocated(srcArray) =
 F , allocated(destArray) =  T

Note that this loss of data only happens for `character` allocatables, not for
array allocatables.
  • [Bug libfortran/72790] N... nathanael.huebbe at informatik dot uni-hamburg.de

Reply via email to