https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125610
Bug ID: 125610
Summary: Bogus runtime error: Assignment of scalar to
unallocated array
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: townsend at astro dot wisc.edu
Target Milestone: ---
The following code causes the run-time error:
At line 49 of file test_scalar_alloc.f90
Fortran runtime error: Assignment of scalar to unallocated array
...when compiled with -fcheck=all.
---
module foo_m
implicit none
type :: foo_t
end type foo_t
interface foo_factory
module procedure foo_factory_0_
module procedure foo_factory_1_
end interface foo_factory
private
public :: foo_t
public :: foo_factory
contains
function foo_factory_0_(i) result(foo)
integer, intent(in) :: i
class(foo_t), allocatable :: foo
foo = foo_t()
end function foo_factory_0_
function foo_factory_1_(i) result(foo)
integer, intent(in) :: i(:)
class(foo_t), allocatable :: foo(:)
allocate(foo_t::foo(SIZE(i)))
end function foo_factory_1_
end module foo_m
program test_scalar_alloc
use foo_m
implicit none
integer :: i(3)
class(foo_t), allocatable :: foo(:)
foo = foo_factory(i)
end program test_scalar_alloc
---
It seems the foo_factory() generic is getting resolved to foo_factory_0_, when
it should resolve to foo_factory_1_.