Index: flang/runtime/io-stmt.h =================================================================== --- flang/runtime/io-stmt.h +++ flang/runtime/io-stmt.h @@ -293,6 +293,9 @@ class ListDirectedStatementState : public FormattedIoStatementState { public: + bool inNamelistArray() const { return inNamelistArray_; } + void set_inNamelistArray(bool yes = true) { inNamelistArray_ = yes; } + // Skips value separators, handles repetition and null values. // Vacant when '/' appears; present with descriptor == ListDirectedNullValue // when a null value appears. @@ -303,10 +306,11 @@ // input statement. This member function resets some state so that // repetition and null values work correctly for each successive // NAMELIST input item. - void ResetForNextNamelistItem() { + void ResetForNextNamelistItem(bool inNamelistArray) { remaining_ = 0; eatComma_ = false; realPart_ = imaginaryPart_ = false; + inNamelistArray_ = inNamelistArray; } private: @@ -316,6 +320,7 @@ bool hitSlash_{false}; // once '/' is seen, nullify further items bool realPart_{false}; bool imaginaryPart_{false}; + bool inNamelistArray_{false}; }; template Index: flang/runtime/namelist.cpp =================================================================== --- flang/runtime/namelist.cpp +++ flang/runtime/namelist.cpp @@ -475,7 +475,7 @@ } io.HandleRelativePosition(byteCount); // Read the values into the descriptor. An array can be short. - listInput->ResetForNextNamelistItem(); + listInput->ResetForNextNamelistItem(useDescriptor->rank() > 0); if (!descr::DescriptorIO(io, *useDescriptor)) { return false; } @@ -494,8 +494,9 @@ } bool IsNamelistName(IoStatementState &io) { - if (io.get_if>()) { - if (io.mutableModes().inNamelist) { + if (auto *listInput{ + io.get_if>()}) { + if (listInput->inNamelistArray()) { SavedPosition savedPosition{io}; std::size_t byteCount{0}; if (auto ch{io.GetNextNonBlank(byteCount)}) {