static bool
flag_fn_result_spec (gfc_expr *expr,
- gfc_symbol *sym ATTRIBUTE_UNUSED,
+ gfc_symbol *sym,
int *f ATTRIBUTE_UNUSED)
{
gfc_namespace *ns;
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)
{
}
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);
}
--- /dev/null
+! { 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