This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR80657 - [7/8/9 Regression] Loop in character function declaration
- From: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 19 May 2018 11:39:50 +0100
- Subject: [Patch, fortran] PR80657 - [7/8/9 Regression] Loop in character function declaration
I intend to commit this as 'obvious' once the patches for PR82923 and
82275 are out of the way.
Paul
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.
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 260389)
--- gcc/fortran/resolve.c (working copy)
*************** resolve_equivalence (gfc_equiv *eq)
*** 16217,16223 ****
static bool
flag_fn_result_spec (gfc_expr *expr,
! gfc_symbol *sym ATTRIBUTE_UNUSED,
int *f ATTRIBUTE_UNUSED)
{
gfc_namespace *ns;
--- 16217,16223 ----
static bool
flag_fn_result_spec (gfc_expr *expr,
! gfc_symbol *sym,
int *f ATTRIBUTE_UNUSED)
{
gfc_namespace *ns;
*************** flag_fn_result_spec (gfc_expr *expr,
*** 16230,16235 ****
--- 16230,16242 ----
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)
{
*************** resolve_fntype (gfc_namespace *ns)
*** 16312,16318 ****
}
if (sym->ts.type == BT_CHARACTER)
! gfc_traverse_expr (sym->ts.u.cl->length, NULL, flag_fn_result_spec, 0);
}
--- 16319,16325 ----
}
if (sym->ts.type == BT_CHARACTER)
! gfc_traverse_expr (sym->ts.u.cl->length, sym, flag_fn_result_spec, 0);
}
Index: gcc/testsuite/gfortran.dg/char_result_18.f90
===================================================================
*** gcc/testsuite/gfortran.dg/char_result_18.f90 (nonexistent)
--- gcc/testsuite/gfortran.dg/char_result_18.f90 (working copy)
***************
*** 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