This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/46174] New: [OOP] ALLOCATE with SOURCE: Deep copy missing


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46174

           Summary: [OOP] ALLOCATE with SOURCE: Deep copy missing
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: janus@gcc.gnu.org


The following is in a sense a follow up to PR 45451.

Assuming that X and Y are both polymorphic (CLASS) and the following operation:
  ALLOCATE (x, SOURCE=y)
or
  x = y ! Fortran 2008: (Re)alloc on assignment with polymorphic LHS

In those cases, one might need to do a deep copy as the polymorphic item might
have allocatable components. This currently does not work.

Example:

  1  2  3  4  5  6  7  8  9 10
 11 12 13 14 15 16 17 18 19 20
 11 12 13 14 15 16 17 18 19 20
Aborted (core dumped)

The third line should be the same as the first one - but in reality it still
points to the allocatable components of the SOURCE=.


implicit none
type t
end type t

type, extends(t) :: t2
  integer, allocatable :: a(:)
end type t2

class(t), allocatable :: x, y
integer :: i

allocate(t2 :: x)
select type(x)
 type is (t2)
   allocate(x%a(10))
   x%a = [ (i, i = 1,10) ]
   print '(*(i3))', x%a
 class default
   call abort()
end select

allocate(y, source=x)

select type(x)
 type is (t2)
   x%a = [ (i, i = 11,20) ]
   print '(*(i3))', x%a
 class default
   call abort()
end select

select type(y)
 type is (t2)
   print '(*(i3))', y%a
   if (any (y%a /= [ (i, i = 1,10) ])) call abort()
 class default
   call abort()
end select
end


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]