[Bug fortran/67562] New: Bad result from sourced allocation with class(*) arrays

neil.n.carlson at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Sep 12 23:14:00 GMT 2015


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

            Bug ID: 67562
           Summary: Bad result from sourced allocation with class(*)
                    arrays
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neil.n.carlson at gmail dot com
  Target Milestone: ---

The following example produces incorrect results from the sourced allocation
involving class(*) arrays.  Perhaps the same as 64692, but that is reported as
fixed.

Expected output:
 source=           1           2
 copy=             1           2 (expect same as source)

But getting this:
 source=           1           2
 copy=             2           0 (expect same as source)

module any_vector_type

  type :: any_vector
    class(*), allocatable :: x(:)
  end type

  interface any_vector
    procedure any_vector_init
  end interface

contains

  function any_vector_init (x) result (this)
    class(*), intent(in) :: x(:)
    type(any_vector) :: this
    call fubar (this, x)
  end function

  subroutine fubar (this, x)
    class(any_vector), intent(out) :: this
    class(*), intent(in) :: x(:)
    allocate(this%x(lbound(x,1):ubound(x,1)), source=x)
    select type (x)
    type is (integer)
      print *, 'source=', x
    end select
    select type (y => this%x)
    type is (integer)
      print *, 'copy=  ', y, '(expect same as source)'
    end select
  end subroutine

end module

program main
  use any_vector_type
  type(any_vector) :: a
  a = any_vector([1,2])
end program



More information about the Gcc-bugs mailing list