diff --git a/flang-rt/lib/runtime/namelist.cpp b/flang-rt/lib/runtime/namelist.cpp index 79dbe4b822921..fbc71faa52416 100644 --- a/flang-rt/lib/runtime/namelist.cpp +++ b/flang-rt/lib/runtime/namelist.cpp @@ -596,6 +596,12 @@ bool IODEF(InputNamelist)(Cookie cookie, const NamelistGroup &group) { } if (next && *next == '/') { io.HandleRelativePosition(byteCount); + if (auto *listInput{ + io.get_if>()}) { + // Don't let the namelist's terminal '/' mess up a parent I/O's + // list-directed input. + listInput->set_hitSlash(false); + } } else if (*next && (*next == '&' || *next == '$')) { // stop at beginning of next group } else {