Commit 9ad8aaf8 by Paul Thomas

re PR fortran/80657 (Loop in character function declaration)

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
parent f82f425b
......@@ -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);
}
......
! { 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment