]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: function returning contiguous class array [PR105543]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 6 Dec 2023 19:42:27 +0000 (20:42 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 10 Dec 2023 19:24:53 +0000 (20:24 +0100)
gcc/fortran/ChangeLog:

PR fortran/105543
* resolve.cc (resolve_symbol): For a CLASS-valued function having a
RESULT clause, ensure that attr.class_ok is set for its symbol as
well as for its resolved result variable.

gcc/testsuite/ChangeLog:

PR fortran/105543
* gfortran.dg/contiguous_13.f90: New test.

gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/contiguous_13.f90 [new file with mode: 0644]

index 166b702cd9a64b6f2bfede69b0011909b206dc25..4fe0e7202e5d0fa2edbe7a99fcb1354bfcb12d53 100644 (file)
@@ -16102,6 +16102,11 @@ resolve_symbol (gfc_symbol *sym)
       specification_expr = saved_specification_expr;
     }
 
+  /* For a CLASS-valued function with a result variable, affirm that it has
+     been resolved also when looking at the symbol 'sym'.  */
+  if (mp_flag && sym->ts.type == BT_CLASS && sym->result->attr.class_ok)
+    sym->attr.class_ok = sym->result->attr.class_ok;
+
   if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived
       && CLASS_DATA (sym))
     {
diff --git a/gcc/testsuite/gfortran.dg/contiguous_13.f90 b/gcc/testsuite/gfortran.dg/contiguous_13.f90
new file mode 100644 (file)
index 0000000..8c67844
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! PR fortran/105543 - function returning contiguous class array
+! Contributed by martin <mscfd@gmx.net>
+
+module func_contiguous
+  implicit none
+  type :: a
+  end type a
+contains
+  function create1 () result(x)
+    class(a), dimension(:), contiguous, pointer :: x
+  end
+  function create2 ()
+    class(a), dimension(:), contiguous, pointer :: create2
+  end
+  function create3 () result(x)
+    class(*), dimension(:), contiguous, pointer :: x
+  end
+  function create4 ()
+    class(*), dimension(:), contiguous, pointer :: create4
+  end
+end module func_contiguous