}
+/* Check for invalid uses of statement function dummy arguments in body. */
+
+static bool
+chk_stmt_fcn_body (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED)
+{
+ gfc_formal_arglist *formal;
+
+ if (e == NULL || e->symtree == NULL || e->expr_type != EXPR_FUNCTION)
+ return false;
+
+ for (formal = sym->formal; formal; formal = formal->next)
+ {
+ if (formal->sym == e->symtree->n.sym)
+ {
+ gfc_error ("Invalid use of statement function argument at %L",
+ &e->where);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
/* Match a statement function declaration. It is so easy to match
non-statement function statements with a MATCH_ERROR as opposed to
MATCH_NO that we suppress error message in most cases. */
return MATCH_ERROR;
}
+ if (gfc_traverse_expr (expr, sym, chk_stmt_fcn_body, 0))
+ return MATCH_ERROR;
+
sym->value = expr;
if ((gfc_current_state () == COMP_FUNCTION
--- /dev/null
+! { dg-do compile }
+! PR fortran/69604
+! Contributed by G.Steinmetz
+
+program p
+ x(n) = 1 + n(2.0) ! { dg-error "Invalid use of statement function argument" }
+ y(k) = k() ! { dg-error "Invalid use of statement function argument" }
+ z(m) = m ! { dg-warning "Statement function" }
+ print *, x(n)
+end