Fortran: fix checking of elemental functions of type CLASS
authorHarald Anlauf <anlauf@gmx.de>
Fri, 10 Dec 2021 21:41:24 +0000 (22:41 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 11 Dec 2021 20:49:47 +0000 (21:49 +0100)
gcc/fortran/ChangeLog:

PR fortran/103606
* resolve.c (resolve_fl_procedure): Do not access CLASS components
before class container has been built.

gcc/testsuite/ChangeLog:

PR fortran/103606
* gfortran.dg/pr103606.f90: New test.

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

index 0ed3197..bff1b35 100644 (file)
@@ -13294,7 +13294,8 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
 
   /* An elemental function is required to return a scalar 12.7.1  */
   if (sym->attr.elemental && sym->attr.function
-      && (sym->as || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as)))
+      && (sym->as || (sym->ts.type == BT_CLASS && sym->attr.class_ok
+                     && CLASS_DATA (sym)->as)))
     {
       gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
                 "result", sym->name, &sym->declared_at);
diff --git a/gcc/testsuite/gfortran.dg/pr103606.f90 b/gcc/testsuite/gfortran.dg/pr103606.f90
new file mode 100644 (file)
index 0000000..4328318
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/103606 -  ICE in resolve_fl_procedure
+! Contributed by G.Steinmetz
+
+program p
+  type t
+  end type
+contains
+  elemental function f() result(z) ! { dg-error "CLASS variable" }
+    class(t) :: z
+  end
+end