https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125632

--- Comment #3 from Steve Kargl <kargl at gcc dot gnu.org> ---
This catches the issue raised by John.  But, f2023:C15104 has several 'or'
clauses and 8 conditions.  I have not checked whether gfortran catches all
of the combinations.  In particular, (2) in the list is pointer assignment,
so replacing the ordinary assignment with 'res => some_target' in John's
example is invalid Fortran.


diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 19a7a2b3378..732fbda77c7 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -13133,6 +13133,17 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace
*ns)
   lhs = code->expr1;
   rhs = code->expr2;

+  /* F2023:C15104 (1) */
+  if ((lhs->symtree->n.sym->attr.use_assoc
+       || lhs->symtree->n.sym->attr.host_assoc)
+      && gfc_pure(NULL))
+    {
+      gfc_error ("Variable in an ordinary assignment at %L is USE or "
+                "host associated in a pure procedure",
+                &lhs->where);
+      return false;
+    }
+
   if ((lhs->symtree->n.sym->ts.type == BT_DERIVED
        || lhs->symtree->n.sym->ts.type == BT_CLASS)
       && !lhs->symtree->n.sym->attr.proc_pointer

Reply via email to