+ /* If there is no extra comma signifying the "format" form of the IO
+ statement, then this must be an error. */
+ if (!dt->extra_comma)
+ {
+ gfc_error ("UNIT specification at %L must be an INTEGER expression "
+ "or a CHARACTER variable", &e->where);
+ return FAILURE;
+ }
+ else
+ {
+ /* At this point, we have an extra comma. If io_unit has arrived as
+ type character, we assume its really the "format" form of the I/O
+ statement. We set the io_unit to the default unit and format to
+ the character expression. See F95 Standard section 9.4. */
+ io_kind k;
+ k = dt->extra_comma->value.iokind;
+ if (e->ts.type == BT_CHARACTER && (k == M_READ || k == M_PRINT))
+ {
+ dt->format_expr = dt->io_unit;
+ dt->io_unit = default_unit (k);
+
+ /* Free this pointer now so that a warning/error is not triggered
+ below for the "Extension". */
+ gfc_free_expr (dt->extra_comma);
+ dt->extra_comma = NULL;
+ }
+
+ if (k == M_WRITE)
+ {
+ gfc_error ("Invalid form of WRITE statement at %L, UNIT required",
+ &dt->extra_comma->where);
+ return FAILURE;
+ }
+ }