diff --git a/flang/include/flang/Parser/message.h b/flang/include/flang/Parser/message.h --- a/flang/include/flang/Parser/message.h +++ b/flang/include/flang/Parser/message.h @@ -214,19 +214,13 @@ public: Messages() {} Messages(Messages &&that) : messages_{std::move(that.messages_)} { - if (!messages_.empty()) { - last_ = that.last_; - that.ResetLastPointer(); - } + RestoreLast(); + that.RestoreLast(); } Messages &operator=(Messages &&that) { messages_ = std::move(that.messages_); - if (messages_.empty()) { - ResetLastPointer(); - } else { - last_ = that.last_; - that.ResetLastPointer(); - } + RestoreLast(); + that.RestoreLast(); return *this; } @@ -240,11 +234,9 @@ } void Annex(Messages &&that) { - if (!that.messages_.empty()) { - messages_.splice_after(last_, that.messages_); - last_ = that.last_; - that.ResetLastPointer(); - } + messages_.splice_after(last_, that.messages_); + RestoreLast(); + that.RestoreLast(); } void Restore(Messages &&that) { @@ -262,7 +254,15 @@ bool AnyFatalError() const; private: - void ResetLastPointer() { last_ = messages_.before_begin(); } + void RestoreLast() { + last_ = messages_.before_begin(); + auto next{messages_.begin()}; + auto end{messages_.end()}; + while (next != end) { + last_ = next; + ++next; + } + } std::forward_list messages_; std::forward_list::iterator last_{messages_.before_begin()}; diff --git a/flang/lib/Parser/message.cpp b/flang/lib/Parser/message.cpp --- a/flang/lib/Parser/message.cpp +++ b/flang/lib/Parser/message.cpp @@ -262,7 +262,7 @@ void Messages::clear() { messages_.clear(); - ResetLastPointer(); + RestoreLast(); } bool Messages::Merge(const Message &msg) { @@ -289,7 +289,7 @@ ++last_; } } - that.ResetLastPointer(); + that.RestoreLast(); } }