goto cleanup;
}
- /* Use the machinery for an initialization expression to reduce the
- stop-code to a constant. */
- gfc_reduce_init_expr (e);
-
- /* Test for F2008 style STOP stop-code. */
- if (e->expr_type != EXPR_CONSTANT && f08)
+ /* If this is F2008, it could be an init expression. */
+ if (f08)
{
- gfc_error ("STOP code at %L must be a scalar default CHARACTER or "
- "INTEGER constant expression", &e->where);
- goto cleanup;
+ gfc_reduce_init_expr (e);
+ if (e->expr_type != EXPR_CONSTANT)
+ {
+ gfc_error ("STOP code at %L must be a scalar constant "
+ "expression", &e->where);
+ goto cleanup;
+ }
}
- if (!(e->ts.type == BT_CHARACTER || e->ts.type == BT_INTEGER))
+ /* For types known at parse time, check immediately. For BT_UNKNOWN
+ (e.g. a forward-referenced contained function) defer to resolve. */
+ if (e->ts.type != BT_UNKNOWN
+ && !(e->ts.type == BT_CHARACTER || e->ts.type == BT_INTEGER))
{
gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
&e->where);
case EXEC_STOP:
case EXEC_ERROR_STOP:
+ if (code->expr1 != NULL && t)
+ {
+ if (!(code->expr1->ts.type == BT_CHARACTER
+ || code->expr1->ts.type == BT_INTEGER))
+ gfc_error ("STOP code at %L must be either INTEGER or CHARACTER "
+ "type", &code->expr1->where);
+ else if (code->expr1->rank != 0)
+ gfc_error ("STOP code at %L must be scalar",
+ &code->expr1->where);
+ else if (code->expr1->ts.type == BT_CHARACTER
+ && code->expr1->ts.kind != gfc_default_character_kind)
+ gfc_error ("STOP code at %L must be default character KIND=%d",
+ &code->expr1->where, (int) gfc_default_character_kind);
+ else if (code->expr1->ts.type == BT_INTEGER
+ && code->expr1->ts.kind != gfc_default_integer_kind)
+ gfc_notify_std (GFC_STD_F2018, "STOP code at %L must be default "
+ "integer KIND=%d", &code->expr1->where,
+ (int) gfc_default_integer_kind);
+ }
if (code->expr2 != NULL
&& (code->expr2->ts.type != BT_LOGICAL
|| code->expr2->rank != 0))
--- /dev/null
+! { dg-do compile }
+! PR fortran/126018 - Stop code may be a function call (CHARACTER or INTEGER)
+program p
+ implicit none
+ error stop character_stop () ! was: "must be either INTEGER or CHARACTER"
+ stop integer_stop () ! likewise for integer
+contains
+ character (1) function character_stop ()
+ character_stop = "a"
+ end function character_stop
+ integer function integer_stop ()
+ integer_stop = 1
+ end function integer_stop
+end program p