]> gcc.gnu.org Git - gcc.git/commitdiff
Fortran - allow target of pointer from evaluation of function-reference
authorHarald Anlauf <anlauf@gmx.de>
Sat, 24 Apr 2021 18:38:06 +0000 (20:38 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 27 Apr 2021 21:11:45 +0000 (23:11 +0200)
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)

gcc/fortran/expr.c
gcc/testsuite/gfortran.dg/ptr-func-4.f90 [new file with mode: 0644]

index 92a6700568d6aee4e7fd493a690d7220f3d38639..956003ec605e46545cb73876a148d4835b72bc06 100644 (file)
@@ -6121,7 +6121,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"
diff --git a/gcc/testsuite/gfortran.dg/ptr-func-4.f90 b/gcc/testsuite/gfortran.dg/ptr-func-4.f90
new file mode 100644 (file)
index 0000000..62b18f6
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-O2 -std=f2008" }
+! PR fortran/100218 - target of pointer from evaluation of function-reference
+
+program p
+  implicit none
+  integer, target :: z = 0
+  call g (f ())
+  if (z /= 1) stop 1
+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
This page took 0.103263 seconds and 5 git commands to generate.