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"
Submitted: https://gcc.gnu.org/pipermail/fortran/2021-April/055976.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:32c4d970ea3a9fc330d6aa8fd83f9dae0b9afc64 commit r12-106-g32c4d970ea3a9fc330d6aa8fd83f9dae0b9afc64 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Apr 24 20:38:06 2021 +0200 Fortran - allow target of pointer from evaluation of function-reference Fortran allows the target of a pointer from the evaluation of a function-reference in a variable definition context (e.g. F2018:R902). gcc/fortran/ChangeLog: PR fortran/100218 * expr.c (gfc_check_vardef_context): Extend check to allow pointer from a function reference. gcc/testsuite/ChangeLog: PR fortran/100218 * gfortran.dg/ptr-func-4.f90: New test.
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:5aee8c2a33ae0d3f375ed0ca6e03718b284d2574 commit r11-8308-g5aee8c2a33ae0d3f375ed0ca6e03718b284d2574 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Apr 24 20:38:06 2021 +0200 Fortran - allow target of pointer from evaluation of function-reference Fortran allows the target of a pointer from the evaluation of a function-reference in a variable definition context (e.g. F2018:R902). gcc/fortran/ChangeLog: PR fortran/100218 * expr.c (gfc_check_vardef_context): Extend check to allow pointer from a function reference. gcc/testsuite/ChangeLog: PR fortran/100218 * gfortran.dg/ptr-func-4.f90: New test. (cherry picked from commit 32c4d970ea3a9fc330d6aa8fd83f9dae0b9afc64)
Fixed on mainline for gcc-12, and on 11-branch. Closing.