IostatBadUnitNumber,
IostatBadFlushUnit,
IostatBadOpOnChildUnit,
+ IostatBadNewUnit,
};
const char *IostatErrorString(int);
IostatBadOpOnChildUnit, nullptr /* no unit */, sourceFile,
sourceLine);
} else {
- return &unit->BeginIoStatement<OpenStatementState>(
- terminator, *unit, wasExtant, sourceFile, sourceLine);
+ return &unit->BeginIoStatement<OpenStatementState>(terminator, *unit,
+ wasExtant, false /*not NEWUNIT=*/, sourceFile, sourceLine);
}
} else {
return NoopUnit(terminator, unitNumber, IostatBadUnitNumber);
Terminator terminator{sourceFile, sourceLine};
ExternalFileUnit &unit{
ExternalFileUnit::NewUnit(terminator, false /*not child I/O*/)};
- return &unit.BeginIoStatement<OpenStatementState>(
- terminator, unit, false /*was an existing file*/, sourceFile, sourceLine);
+ return &unit.BeginIoStatement<OpenStatementState>(terminator, unit,
+ false /*was an existing file*/, true /*NEWUNIT=*/, sourceFile,
+ sourceLine);
}
Cookie IONAME(BeginWait)(ExternalUnit unitNumber, AsynchronousId id,
SignalError("FILE= may not appear on OPEN with STATUS='SCRATCH'");
}
}
+ // F'2023 12.5.6.13 - NEWUNIT= requires either FILE= or STATUS='SCRATCH'
+ if (isNewUnit_ && !path_.get() &&
+ status_.value_or(OpenStatus::Unknown) != OpenStatus::Scratch) {
+ SignalError(IostatBadNewUnit);
+ status_ = OpenStatus::Scratch; // error recovery
+ }
if (path_.get() || wasExtant_ ||
(status_ && *status_ == OpenStatus::Scratch)) {
unit().OpenUnit(status_, action_, position_.value_or(Position::AsIs),
// OPEN
class OpenStatementState : public ExternalIoStatementBase {
public:
- OpenStatementState(ExternalFileUnit &unit, bool wasExtant,
+ OpenStatementState(ExternalFileUnit &unit, bool wasExtant, bool isNewUnit,
const char *sourceFile = nullptr, int sourceLine = 0)
- : ExternalIoStatementBase{unit, sourceFile, sourceLine}, wasExtant_{
- wasExtant} {}
+ : ExternalIoStatementBase{unit, sourceFile, sourceLine},
+ wasExtant_{wasExtant}, isNewUnit_{isNewUnit} {}
bool wasExtant() const { return wasExtant_; }
void set_status(OpenStatus status) { status_ = status; } // STATUS=
void set_path(const char *, std::size_t); // FILE=
private:
bool wasExtant_;
+ bool isNewUnit_;
std::optional<OpenStatus> status_;
std::optional<Position> position_;
std::optional<Action> action_;
return "FLUSH attempted on a bad or unconnected unit number";
case IostatBadOpOnChildUnit:
return "Impermissible I/O statement on child I/O unit";
+ case IostatBadNewUnit:
+ return "NEWUNIT= without FILE= or STATUS='SCRATCH'";
default:
return nullptr;
}