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

            Bug ID: 86115
           Summary: move_alloc for class(*) containing value of type
                    character(len=*) looses data
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mscfd at gmx dot net
  Target Milestone: ---

related: bug 72790

Applying move_alloc(x,y) for x and y both declared as class(*) and x currently
containing a string (character(len=...)) fails. The type seems to be
transfered, but the value is empty.

Test case, which shows that for integer variables move_alloc works as expected,
but which fails for strings:

program movealloc

   class(*), allocatable :: x, y, s, t

   allocate(x, source=1234)
   allocate(s, source='5678')

   call p(x)
   call p(y)
   call p(s)
   call p(t)
   call move_alloc(x, y)
   call move_alloc(s, t)
   print *,'---'
   call p(x)
   call p(y)
   call p(s)
   call p(t)


contains

   subroutine p(z)
      class(*), allocatable, intent(in) :: z

      if (allocated(z)) then
         select type(z)
         type is (character(len=*))
            print *, 'string: ', z
         type is (integer)
            print *, 'integer: ', z
         class default
            print *, 'unknown type'
         end select

      else
         print *, 'not allocated'
      end if
   end subroutine p

end program


expected output (confirmed with ifort):
 integer:         1234
 not allocated
 string: 5678
 not allocated
 ---
 not allocated
 integer:         1234
 not allocated
 string: 5678


gfortran output:
 integer:         1234
 not allocated
 string: 5678
 not allocated
 ---
 not allocated
 integer:         1234
 not allocated
 string: 

(not that it does not report 'unknown type')

Reply via email to