re PR fortran/80657 (Loop in character function declaration)
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 10:08:24 +0000 (10:08 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 10:08:24 +0000 (10:08 +0000)
2018-05-19  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/80657
* resolve.c (flag_fn_result_spec): Use the 'sym' argument to
test for self refs to the function result in the character len
expression. If a self reference is found, emit an error and
return true.
(resolve_fntype): Use the function symbol in the calls to the
above.

2018-05-19  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/80657
* gfortran.dg/char_result_18.f90: New test.

From-SVN: r260415

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/char_result_18.f90 [new file with mode: 0644]

index 913320cc669b579653c96eb72020ed0e6ea50a08..13374dddf1dc7a891c89612bf48e94ffc511c6ca 100644 (file)
@@ -16217,7 +16217,7 @@ resolve_equivalence (gfc_equiv *eq)
 
 static bool
 flag_fn_result_spec (gfc_expr *expr,
-                     gfc_symbol *sym ATTRIBUTE_UNUSED,
+                     gfc_symbol *sym,
                      int *f ATTRIBUTE_UNUSED)
 {
   gfc_namespace *ns;
@@ -16230,6 +16230,13 @@ flag_fn_result_spec (gfc_expr *expr,
        if (!ns->parent)
          break;
 
+      if (sym == s)
+       {
+         gfc_error ("Self reference in character length expression "
+                    "for %qs at %L", sym->name, &expr->where);
+         return true;
+       }
+
       if (!s->fn_result_spec
          && s->attr.flavor == FL_PARAMETER)
        {
@@ -16312,7 +16319,7 @@ resolve_fntype (gfc_namespace *ns)
       }
 
   if (sym->ts.type == BT_CHARACTER)
-    gfc_traverse_expr (sym->ts.u.cl->length, NULL, flag_fn_result_spec, 0);
+    gfc_traverse_expr (sym->ts.u.cl->length, sym, flag_fn_result_spec, 0);
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/char_result_18.f90 b/gcc/testsuite/gfortran.dg/char_result_18.f90
new file mode 100644 (file)
index 0000000..f47c88a
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+!
+! Tests the fix for PR80657.
+!
+! Contributed by Vittorio Zecca  <zeccav@gmail.com>
+!
+function f(x)
+implicit character(len(f)) (x) ! { dg-error "Self reference in character length" }
+character(len(x)) f
+end