Index: flang/runtime/io-stmt.h =================================================================== --- flang/runtime/io-stmt.h +++ flang/runtime/io-stmt.h @@ -220,7 +220,7 @@ // Skips spaces, advances records, and ignores NAMELIST comments std::optional GetNextNonBlank() { auto ch{GetCurrentChar()}; - bool inNamelist{GetConnectionState().modes.inNamelist}; + bool inNamelist{mutableModes().inNamelist}; while (!ch || *ch == ' ' || *ch == '\t' || (inNamelist && *ch == '!')) { if (ch && (*ch == ' ' || *ch == '\t')) { HandleRelativePosition(1); Index: flang/runtime/namelist.cpp =================================================================== --- flang/runtime/namelist.cpp +++ flang/runtime/namelist.cpp @@ -28,9 +28,9 @@ bool IONAME(OutputNamelist)(Cookie cookie, const NamelistGroup &group) { IoStatementState &io{*cookie}; io.CheckFormattedStmtType("OutputNamelist"); - ConnectionState &connection{io.GetConnectionState()}; - connection.modes.inNamelist = true; + io.mutableModes().inNamelist = true; char comma{static_cast(GetComma(io))}; + ConnectionState &connection{io.GetConnectionState()}; // Internal functions to advance records and convert case const auto EmitWithAdvance{[&](char ch) -> bool { return (!connection.NeedAdvance(1) || io.AdvanceRecord()) && @@ -355,8 +355,7 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) { IoStatementState &io{*cookie}; io.CheckFormattedStmtType("InputNamelist"); - ConnectionState &connection{io.GetConnectionState()}; - connection.modes.inNamelist = true; + io.mutableModes().inNamelist = true; IoErrorHandler &handler{io.GetIoErrorHandler()}; auto *listInput{io.get_if>()}; RUNTIME_CHECK(handler, listInput != nullptr); @@ -485,8 +484,7 @@ bool IsNamelistName(IoStatementState &io) { if (io.get_if>()) { - ConnectionState &connection{io.GetConnectionState()}; - if (connection.modes.inNamelist) { + if (io.mutableModes().inNamelist) { SavedPosition savedPosition{io}; if (auto ch{io.GetNextNonBlank()}) { if (IsLegalIdStart(*ch)) {