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

Harald Anlauf <anlauf at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2026-06-04
     Ever confirmed|0                           |1

--- Comment #1 from Harald Anlauf <anlauf at gcc dot gnu.org> ---
(In reply to Rich Townsend from comment #0)
> 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.

Confirmed.

It is already -fcheck=mem that triggers.

> 
> ---
> 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_.

No.  When I ddd a print into foo_factory_1_, or comment the line

!       module procedure foo_factory_0_

I get the same error.

Reply via email to