Avoid a loop closure issue that caused incorrect sequence lookups.

Fixes a regression from #5234 that is only apparent on older compilers.