public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/44541]  New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
@ 2010-06-15  7:45 burnus at gcc dot gnu dot org
  2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-06-15  7:45 UTC (permalink / raw)
  To: gcc-bugs

Follow up to PR 43388 (ALLOCATE with MOLD, a F2008 feature), but it also
applies to polymorphic variables with INTENT(OUT) (i.e. to F2003).

In either cases, a potentially existing default initializer of the *effective
type* needs to be applied. That means that this data has to be available in the
vtable.

See also: http://j3-fortran.org/pipermail/j3/2010-June/003621.html

(Thanks to Janus for spotting the problem (for MOLD) at the first place; thanks
to Bill Long for confirmation and mentioning INTENT(OUT); and to Aleksandar
Donev for the comments.)

Testing shows that other vendors have also overlooked these cases.
(For intent out, there seem to be compiler which do not set the variable at all
(e.g. gfortran) or those which only use the base type for the initialization;
similarly, for MOLD where unspecified initialization happens (via malloc),
possibly with base-type initialization on top.)

---------- INTENT(OUT) test case -----------------
! Expected: a= 1  b= 3
  implicit none
  type t
    integer :: a = 1
  end type t
  type, extends(t) :: t2
    integer :: b = 3
  end type t2

  type(t2) :: y
  y%a = 44
  y%b = 55
  call intent_out (y)
  print *, 'a=', y%a, ' b=', y%b
contains
  subroutine intent_out(x)
    class(t), intent(out) :: x
    select type (x)
      type is (t2)
      print *, 'a=', x%a, ' b=', x%b
    end select
  end subroutine
end

---------- MOLD test case ------------------------
! Expected:
!  a= 1  b= 3
! (Wrong is "a= 1  b= 0" or "a= 0  b= 0" or garbage)
implicit none
type t
  integer :: a = 1
end type t

type, extends(t) :: t2
  integer :: b = 3
end type t2

class(t), allocatable :: x, y

allocate (t2 :: y)
select type (y)
  type is (t2)
    y%a = 44
    y%b = 55
end select

allocate ( x, mold=y)
select type (x)
  type is (t2)
   print *, 'a=', x%a, ' b=', x%b
end select
end


-- 
           Summary: [OOP] wrong code for polymorphic variable with
                    INTENT(OUT)/Alloc w/ MOLD
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org
 BugsThisDependsOn: 43388


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


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

end of thread, other threads:[~2010-09-02 12:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
2010-06-21 10:18 ` janus at gcc dot gnu dot org
2010-08-21 12:51 ` burnus at gcc dot gnu dot org
2010-08-21 15:14 ` janus at gcc dot gnu dot org
2010-08-29 21:10 ` janus at gcc dot gnu dot org
2010-09-01 20:51 ` janus at gcc dot gnu dot org
2010-09-01 21:25 ` burnus at gcc dot gnu dot org
2010-09-02 12:35 ` janus at gcc dot gnu dot 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).