https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122863
Bug ID: 122863
Summary: Allocatable class(*) component causes segfault when
initialized within array constructor
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: baradi09 at gmail dot com
Target Milestone: ---
GIVEN
a derived type with a public allocatable class(*) component
WHEN
a type instance is created within an array constructor
THEN
a segfault occurs.
MINIMAL EXAMPLE
module testmod
implicit none
type :: item
class(*), allocatable :: val
end type item
! ! If this user defined structure constructor is uncommented, no segfault
occurs.
! interface item
! module procedure new_item
! end interface item
contains
subroutine print_item1(items)
type(item), intent(in) :: items(:)
print *, "Value of first item:"
select type (val => items(1)%val)
type is (integer)
print *, val
end select
end subroutine print_item1
! User defined structure constructor as workaround
function new_item(val) result(this)
class(*), intent(in) :: val
type(item) :: this
allocate(this%val, source=val)
end function new_item
end module testmod
program test
use testmod
implicit none
type(item) :: items(1)
items(:) = [item(42)]
call print_item1(items)
end program test
BUILDING AND RUNNING
gfortran test.f90
./a.out
OBSERVED BEHAVIOR
Segfault
EXPECTED BEHAVIOR
Program runs normally.
FURTHER COMMENTS
* When derived type is created outside of an array constructor, the example
seems to work
* When the user defined structure constructor (which is defined, but not used
in the example) is used to override the default constructor, the example works.