https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100218
Bug ID: 100218 Summary: Allow target of the pointer resulting from the evaluation of function-reference in a variable definition context Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: anlauf at gcc dot gnu.org Target Milestone: --- While analyzing PR100154, Tobias pointed me to the following: F2018:R902: function-reference shall have a data pointer result A variable is either the data object denoted by designator or the target of the pointer resulting from the evaluation of function-reference; this pointer shall be associated. He also gave an example in that other PR, for which I have a fix. In my interpretation the following code should thus also be valid and is accepted by two other compilers I tested (Intel, Nvidia) and gives the right result. program p implicit none integer, target :: z = 0 call g (f ()) print *, z contains function f () result (r) integer, pointer :: r r => z end function f subroutine g (x) integer, intent(out) :: x x = 1 end subroutine g end program p The following patch seems to help: diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 92a6700568d..696b9f1daac 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -6121,7 +6132,9 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, bool alloc_obj, } if (!pointer && sym->attr.flavor != FL_VARIABLE && !(sym->attr.flavor == FL_PROCEDURE && sym == sym->result) - && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.proc_pointer)) + && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.proc_pointer) + && !(sym->attr.flavor == FL_PROCEDURE + && sym->attr.function && sym->attr.pointer)) { if (context) gfc_error ("%qs in variable definition context (%s) at %L is not"