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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-10
                 CC|                            |janus at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from janus at gcc dot gnu.org ---
(In reply to Valery Weber from comment #0)
> the following code is compiling fine with 4.9.1, but shouldnt gcc complain
> about calling a nonpure procedure from a pure one?

It definitely should, and the problem also occurs with the 5.0 trunk.

The part that checks for pureness in 'resolve_function' is apparently not
applied to procedure-pointer components, but could e.g. be transferred to
'resolve_expr_ppc' like this:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (Revision 218598)
+++ gcc/fortran/resolve.c    (Arbeitskopie)
@@ -6048,6 +6048,7 @@ static bool
 resolve_expr_ppc (gfc_expr* e)
 {
   gfc_component *comp;
+  const char *name = NULL;

   comp = gfc_get_proc_ptr_comp (e);
   gcc_assert (comp != NULL);
@@ -6074,6 +6075,32 @@ resolve_expr_ppc (gfc_expr* e)
   if (!update_ppc_arglist (e))
     return false;

+  if (!pure_function (e, &name))
+    {
+      if (forall_flag)
+        {
+          gfc_error ("Reference to non-PURE function '%s' at %L inside a "
+                     "FORALL %s", comp->name, &e->where,
+                     forall_flag == 2 ? "mask" : "block");
+          return false;
+        }
+      else if (gfc_do_concurrent_flag)
+        {
+          gfc_error ("Reference to non-PURE function '%s' at %L inside a "
+                     "DO CONCURRENT %s", comp->name, &e->where,
+                     gfc_do_concurrent_flag == 2 ? "mask" : "block");
+          return false;
+        }
+      else if (gfc_pure (NULL))
+        {
+          gfc_error ("Reference to non-PURE function '%s' at %L "
+                     "within a PURE procedure", comp->name, &e->where);
+          return false;
+        }
+
+      gfc_unset_implicit_pure (NULL);
+    }
+
   gfc_ppc_use (comp, &e->value.compcall.actual, &e->where);

   return true;


This is sufficient to trigger the right error for the test case, but more work
needs to be done: 'pure_function' needs to be taught to handle PPCs and one
needs to add a pureness check for procedure-pointer assignments. Finally it
should be checked if the same problem also applies to 'ordinary' procedure
pointers (which are not a type component) and to the case of subroutines
(instead of functions).

Reply via email to