From d8a92570baa8344deaa21ea0cc948a86111ace4b Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 21 Sep 2024 23:26:39 -0400 Subject: [PATCH] Add a comment to explain why ranged-for cannot be used --- lager/detail/nodes.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lager/detail/nodes.hpp b/lager/detail/nodes.hpp index 633be49..f7dabb9 100644 --- a/lager/detail/nodes.hpp +++ b/lager/detail/nodes.hpp @@ -235,6 +235,10 @@ class reader_node : public observable_reader_node bool garbage = false; this->observers()(last_); + // We cannot use ranged-for here because children might + // change as a result of notify(). This can invalidate + // the iterators on children, causing undefined behaviors. + // See also https://github.com/arximboldi/lager/pull/212 const auto& children = this->children(); for (size_t i = 0, size = children.size(); i < size; ++i) { if (auto child = children[i].lock()) {