https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126517
Bug ID: 126517
Summary: Assigning an unallocated allocatable function result
array to an allocatable causes segmentation fault
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mikael at gcc dot gnu.org
Target Milestone: ---
Example assigning (unallocated) allocatable function results to allocatable
variables:
program p
implicit none
type :: t1
integer :: c1
end type
type, extends(t1) :: t2
integer :: c2
end type
type(t1), allocatable :: ta(:)
class(t1), allocatable :: ca(:), ca2(:)
print *, allocated(ta)
ta = t1_alloc()
!print *, allocated(ta)
!allocate(ta(5))
!ta = t1_alloc()
!print *, allocated(ta)
print *, allocated(ca)
ca = t1_alloc()
print *, allocated(ca)
allocate(ca(5))
ca = t1_alloc()
print *, allocated(ca)
print *, allocated(ca2)
!ca2 = class_alloc()
!print *, allocated(ca2)
!allocate(t2 :: ca2(5))
!ca2 = class_alloc()
!print *, allocated(ca2)
contains
function t1_alloc()
type(t1), allocatable :: t1_alloc(:)
end function
function class_alloc()
class(t1), allocatable :: class_alloc(:)
end function
end program
The non commented lines are the ones that work.
Uncommenting the lines either in the first block or in the third one cause a
segfault at runtime.
My expectation is that with all the lines enabled it should print False nine
times.
I think the program is valid, but I can't find anything in the standard
explicitly allowing an allocatable function to return an unallocated value.