https://gcc.gnu.org/g:0bc2e8c5101ab34e597106911710c9ce9565d546

commit r17-1975-g0bc2e8c5101ab34e597106911710c9ce9565d546
Author: Paul Thomas <[email protected]>
Date:   Mon Jun 29 14:43:39 2026 +0100

    Fortran: Correct error in accessing CLASS declared type [PR84622]
    
    2026-06-29  Paul Thomas  <[email protected]>
    
    gcc/fortran
            PR fortran/84622
            * resolve.cc (resolve_symbol): In detecting coarray components,
            use the derived type of the class data component, not the data
            component itself. New boolean 'declared_has_coarray_comp' to
            detect this.
    
    gcc/testsuite/
            PR fortran/84622
            * gfortran.dg/pr84622.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc                |  8 +++++---
 gcc/testsuite/gfortran.dg/pr84622.f90 | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 9f1626c2949e..f07c443b558a 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -18498,6 +18498,7 @@ resolve_symbol (gfc_symbol *sym)
   gfc_component *c;
   symbol_attribute class_attr;
   gfc_array_spec *as;
+  bool declared_has_coarray_comp = false;
 
   if (sym->resolve_symbol_called >= 1)
     return;
@@ -18691,6 +18692,8 @@ skip_interfaces:
       as = CLASS_DATA (sym)->as;
       class_attr = CLASS_DATA (sym)->attr;
       class_attr.pointer = class_attr.class_pointer;
+      declared_has_coarray_comp = CLASS_DATA (sym)->ts.u.derived
+                                 && CLASS_DATA 
(sym)->ts.u.derived->attr.coarray_comp;
     }
   else
     {
@@ -19158,9 +19161,8 @@ skip_interfaces:
   /* F2008, C541.  */
   if ((((sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.coarray_comp)
        || (sym->ts.type == BT_CLASS && sym->attr.class_ok
-           && sym->ts.u.derived && CLASS_DATA (sym)
-           && CLASS_DATA (sym)->attr.coarray_comp))
-       || (class_attr.codimension && class_attr.allocatable))
+           && declared_has_coarray_comp))
+       || (class_attr.codimension && class_attr.allocatable))
       && sym->attr.dummy && sym->attr.intent == INTENT_OUT)
     {
       gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
diff --git a/gcc/testsuite/gfortran.dg/pr84622.f90 
b/gcc/testsuite/gfortran.dg/pr84622.f90
new file mode 100644
index 000000000000..2e2b8f1a54cb
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr84622.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+!
+! Previously s/CLASS/TYPE at line 12 caught the error.
+!
+! Contributed by Damian ROuson  <[email protected]>
+!
+  type foo
+    logical, allocatable :: bar[:]
+  end type
+contains
+  subroutine foobar(this) ! { dg-error "or have coarray components" }
+    class(foo), intent(out) :: this
+  end subroutine
+end

Reply via email to