Hello All, The attached was pushed to mainline as 'obvious', after regression testing; r17-1975
I will backport very soon. Regards Paul
From 3dae659f4a8c110f44f53d1cfcf25c73ad631c36 Mon Sep 17 00:00:00 2001 From: Paul Thomas <[email protected]> Date: Mon, 29 Jun 2026 14:43:39 +0100 Subject: [PATCH] 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. --- gcc/fortran/resolve.cc | 8 +++++--- gcc/testsuite/gfortran.dg/pr84622.f90 | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr84622.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 9f1626c2949..917bacad909 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 00000000000..2e2b8f1a54c --- /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 -- 2.54.0
