public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46174] New: [OOP] ALLOCATE with SOURCE: Deep copy missing
@ 2010-10-25 21:45 burnus at gcc dot gnu.org
  2010-10-26  7:10 ` [Bug fortran/46174] " sfilippone at uniroma2 dot it
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-10-25 21:45 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-11-05 18:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-25 21:45 [Bug fortran/46174] New: [OOP] ALLOCATE with SOURCE: Deep copy missing burnus at gcc dot gnu.org
2010-10-26  7:10 ` [Bug fortran/46174] " sfilippone at uniroma2 dot it
2010-10-26  7:44 ` burnus at gcc dot gnu.org
2010-10-26 13:27 ` burnus at gcc dot gnu.org
2010-10-26 19:00 ` domob at gcc dot gnu.org
2010-11-03  9:18 ` burnus at gcc dot gnu.org
2010-11-05  9:48 ` janus at gcc dot gnu.org
2010-11-05 18:15 ` janus at gcc dot gnu.org
2010-11-05 18:39 ` janus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).