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

            Bug ID: 57456
           Summary: [OOP] CLASS ALLOCATE with typespec: Too little memory
                    allocated
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org

The following seems to ignore the typespec ("t2::") when calculating how much
memory is required to allocate:


module m
  implicit none
  type t
    integer :: i
   end type t
  type, extends(t) :: t2
    integer :: j
   end type t2
end module m

program test
  use m
  implicit none
  integer :: i
  class(t), save, allocatable :: y(:)

  allocate (t2 :: y(5)) ! Should malloc 2*4*5 = 40 bytes, mallocs only 20
  select type(y)
  type is (t2)
    do i = 1, 5
      y(i)%i = i ! "Invalid write of size 4"
    end do
  end select
  deallocate(y) ! SIGABRT: Process abort signal.
end

Reply via email to