@@ -208,20 +208,30 @@ void OpenStatementState::set_path(const char *path, std::size_t length) {
208
208
}
209
209
210
210
int OpenStatementState::EndIoStatement () {
211
+ if (position_) {
212
+ if (access_ && *access_ == Access::Direct) {
213
+ SignalError (" POSITION= may not be set with ACCESS='DIRECT'" );
214
+ position_.reset ();
215
+ }
216
+ }
211
217
if (path_.get () || wasExtant_ ||
212
218
(status_ && *status_ == OpenStatus::Scratch)) {
213
- unit ().OpenUnit (status_, action_, position_, std::move (path_), pathLength_ ,
214
- convert_, *this );
219
+ unit ().OpenUnit (status_, action_, position_. value_or (Position::AsIs) ,
220
+ std::move (path_), pathLength_, convert_, *this );
215
221
} else {
216
- unit ().OpenAnonymousUnit (status_, action_, position_, convert_, *this );
222
+ unit ().OpenAnonymousUnit (
223
+ status_, action_, position_.value_or (Position::AsIs), convert_, *this );
217
224
}
218
225
if (access_) {
219
226
if (*access_ != unit ().access ) {
220
227
if (wasExtant_) {
221
228
SignalError (" ACCESS= may not be changed on an open unit" );
229
+ access_.reset ();
222
230
}
223
231
}
224
- unit ().access = *access_;
232
+ if (access_) {
233
+ unit ().access = *access_;
234
+ }
225
235
}
226
236
if (!unit ().isUnformatted ) {
227
237
unit ().isUnformatted = isUnformatted_;
0 commit comments