https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119948
kargls at comcast dot net changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargls at comcast dot net --- Comment #1 from kargls at comcast dot net --- (In reply to Damian Rouson from comment #0) > % gfortran --version > GNU Fortran (GCC) 15.0.1 20250412 (experimental) > > > If the separate "result" clause is eliminated and the procedure name is > therefore the result name ("test"), then the error message changes to > > > 17 | allocate(test%i, source = 0) > | 1 > Error: ‘test’ at (1) is not a variable With this patch, diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 161d4c26964..44572f136cd 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -4412,6 +4412,11 @@ match_variable (gfc_expr **result, int equiv_flag, int host_flag) || replace_hidden_procptr_result (&sym, &st)) break; + if (sym->attr.function + && sym == sym->result + && gfc_is_function_return_value (sym, gfc_current_ns)) + break; + /* Fall through to error */ gcc_fallthrough (); The following code compiles and executes module test_m implicit none type test_t integer, allocatable :: i end type interface pure module function test() implicit none type(test_t) test end function end interface contains module procedure test allocate(test%i, source = 42) end procedure end module program foo use test_m type(test_t) a a = test() print *, a%i end program foo % gfcx -o z a.f90 && ./z 42 I, however, do not understand lines 4392-4409 in primary.cc.