]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/80657 (Loop in character function declaration)
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 18:08:04 +0000 (18:08 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 18:08:04 +0000 (18:08 +0000)
2018-05-20  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/80657
Backport from trunk
* 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-20  Paul Thomas  <pault@gcc.gnu.org>

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

From-SVN: r260424

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

index ebb6806a530bc1b53f79abcdc35f7a63e7cec841..ff480f2824c90e2f36a40541454c2c85914ffe5b 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-20  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/80657
+       Backport from trunk
+       * 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-20  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82275
index dad746d86fba265ad4024d294275e3e1c2082ca1..ed9b3f1d56546bc9c5d24d544fbe9d57aca65c19 100644 (file)
@@ -15870,7 +15870,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;
@@ -15883,6 +15883,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)
        {
@@ -15965,7 +15972,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);
 }
 
 
index 5f7d356fac112996d477a8714ae2d4b4fad090f0..bac4fc06b7296b5c84e71f29b864f054befa5d5e 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-20  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/80657
+       Backport from trunk
+       * gfortran.dg/char_result_18.f90: New test.
+
 2018-05-20  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82275
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