https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109500
--- Comment #19 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Thu, Apr 20, 2023 at 05:22:59AM +0000, kargl at gcc dot gnu.org wrote: > > I think we agree on all points. Here's the diff I envision. > NOte, I've restricted it to user defined functions. Remove > the esym check will enable it for any subprogram. > > > diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc > index db79b104dc2..f3bcdd76d6a 100644 > --- a/gcc/fortran/interface.cc > +++ b/gcc/fortran/interface.cc > @@ -3622,6 +3622,18 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, > gfc_formal_arglist *formal, > goto match; > } > > + if (a->expr->expr_type == EXPR_FUNCTION > + && a->expr->value.function.esym > + && f->sym->attr.allocatable) > + { > + if (where) > + gfc_error ("Actual argument for %qs at %L is a function result " > + "and the dummy argument is ALLOCATABLE", > + f->sym->name, &a->expr->where); > + ok = false; > + goto match; > + } > + > /* Check intent = OUT/INOUT for definable actual argument. */ > if (!in_statement_function > && (f->sym->attr.intent == INTENT_OUT > The patch passes regtesting. PS: I think what you want to with a runtime check and an undefine function result is a good idea. I haven't looked to see where and how hard this might be to implement.