diff --git a/flang-rt/include/flang-rt/runtime/io-stmt.h b/flang-rt/include/flang-rt/runtime/io-stmt.h index b98422b8707f9..03b6efd65ddfc 100644 --- a/flang-rt/include/flang-rt/runtime/io-stmt.h +++ b/flang-rt/include/flang-rt/runtime/io-stmt.h @@ -458,6 +458,11 @@ class ListDirectedStatementState namelistGroup_ = namelistGroup; } + RT_API_ATTRS bool eatComma() const { return eatComma_; } + RT_API_ATTRS void set_eatComma(bool yes) { eatComma_ = yes; } + RT_API_ATTRS bool hitSlash() const { return hitSlash_; } + RT_API_ATTRS void set_hitSlash(bool yes) { hitSlash_ = yes; } + protected: const NamelistGroup *namelistGroup_{nullptr}; diff --git a/flang-rt/lib/runtime/io-stmt.cpp b/flang-rt/lib/runtime/io-stmt.cpp index 3260c8f83edb9..e260c0ca7511d 100644 --- a/flang-rt/lib/runtime/io-stmt.cpp +++ b/flang-rt/lib/runtime/io-stmt.cpp @@ -1076,6 +1076,14 @@ void ChildFormattedIoStatementState::CompleteOperation() { template int ChildFormattedIoStatementState::EndIoStatement() { + if constexpr (DIR == Direction::Input) { + if (auto *listInput{this->child() + .parent() + .template get_if< + ListDirectedStatementState>()}) { + listInput->set_eatComma(false); + } + } CompleteOperation(); return ChildIoStatementState::EndIoStatement(); } @@ -1097,6 +1105,7 @@ ChildListIoStatementState::ChildListIoStatementState( if constexpr (DIR == Direction::Input) { if (auto *listInput{child.parent() .get_if>()}) { + this->set_eatComma(listInput->eatComma()); this->namelistGroup_ = listInput->namelistGroup(); } } @@ -1121,6 +1130,13 @@ bool ChildListIoStatementState::AdvanceRecord(int n) { template int ChildListIoStatementState::EndIoStatement() { if constexpr (DIR == Direction::Input) { + if (auto *listInput{this->child() + .parent() + .template get_if< + ListDirectedStatementState>()}) { + listInput->set_eatComma(this->eatComma()); + listInput->set_hitSlash(this->hitSlash()); + } if (int status{ListDirectedStatementState::EndIoStatement()}; status != IostatOk) { return status;