https://gcc.gnu.org/g:b21ccc7c211e6a4a5e77f20fd05d65c378f583df
commit r17-6639-gb21ccc7c211e6a4a5e77f20fd05d65c378f583df Author: Jerry DeLisle <[email protected]> Date: Tue Nov 24 09:17:21 2026 -0800 fortran: [PR128976] Bogus INTENT(IN) error for a POINTER selector Since the fix for PR54322, defining the associate name of a CLASS IS block whose selector is a POINTER dummy with INTENT(IN) was rejected, although only a nonpointer INTENT(IN) object is barred from a variable definition context (F2023 C846). The INTENT(IN) check asked whether the associate name was a pointer rather than the dummy argument, and that was true only while the associate name had the POINTER attribute of its class container. Check the dummy argument instead. This also fixes the same bogus error for an element of a polymorphic POINTER INTENT(IN) array. Assisted-by: Claude Opus 5.5 PR fortran/128976 gcc/fortran/ChangeLog: * expr.cc (gfc_check_vardef_context): For INTENT(IN), test the POINTER attribute of the dummy argument, which for a SELECT TYPE temporary is the selector. gcc/testsuite/ChangeLog: * gfortran.dg/pr128976.f90: New test. Diff: --- gcc/fortran/expr.cc | 8 +++--- gcc/testsuite/gfortran.dg/pr128976.f90 | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index d31c807b958c..bca766448eaa 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -6954,8 +6954,9 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, bool alloc_obj, && sym->assoc->target && sym->assoc->target->symtree && sym->assoc->target->symtree->n.sym->attr.intent == INTENT_IN))) { - const char *name = (sym->attr.select_type_temporary - ? sym->assoc->target->symtree->name : sym->name); + gfc_symtree *dummy = (sym->attr.select_type_temporary + ? sym->assoc->target->symtree : e->symtree); + const char *name = dummy->name; if (pointer && is_pointer) { if (context) @@ -6964,7 +6965,8 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, bool alloc_obj, name, context, &e->where); return false; } - if (!pointer && !is_pointer && !sym->attr.pointer) + /* Only a nonpointer INTENT(IN) object is barred here (F2023:C846). */ + if (!pointer && !is_pointer && !IS_POINTER (dummy->n.sym)) { if (context) gfc_error ("Dummy argument %qs with INTENT(IN) in variable" diff --git a/gcc/testsuite/gfortran.dg/pr128976.f90 b/gcc/testsuite/gfortran.dg/pr128976.f90 new file mode 100644 index 000000000000..1637eb61e2b3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr128976.f90 @@ -0,0 +1,48 @@ +! { dg-do compile } +! +! PR 128976 + +module m + implicit none + type :: t1_t + integer :: i = 0 + end type t1_t +contains + subroutine s1 (core) + class(t1_t), intent(in), pointer :: core + select type (core) + class is (t1_t) + call s2 (core) + core%i = 1 + end select + end subroutine s1 + subroutine s3 (core) + class(*), intent(in), pointer :: core + select type (core) + class is (t1_t) + call s2 (core) + type is (integer) + core = 1 + end select + end subroutine s3 + subroutine s4 (core) + class(t1_t), intent(in), pointer :: core(:) + call s2 (core(1)) + select type (core) + class is (t1_t) + core%i = 1 + call s2 (core(2)) + end select + end subroutine s4 + subroutine s5 (core) + class(t1_t), intent(in) :: core + select type (core) + class is (t1_t) + call s2 (core) ! { dg-error "INTENT\\(IN\\)" } + core%i = 1 ! { dg-error "INTENT\\(IN\\)" } + end select + end subroutine s5 + subroutine s2 (core) + class(t1_t), intent(inout) :: core + end subroutine s2 +end module m
