From 47a4ca4f4cbe676e48120ea6faa2f2d3507c0873 Mon Sep 17 00:00:00 2001 From: Frank Birbacher Date: Fri, 15 Aug 2025 18:37:41 +0200 Subject: [PATCH] [hive.erasure]/2 Have erase_if reevaluate end() The defining code must not cache the end-iterator. In case the last element of the sequence is removed, the past-the-end iterator will be invalidated. This will trigger UB in the loop condition. Instead, re-evaluate end() each time. --- source/containers.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/containers.tex b/source/containers.tex index bb8e70dc31..5d8000e785 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -8969,7 +8969,7 @@ Equivalent to: \begin{codeblock} auto original_size = c.size(); -for (auto i = c.begin(), last = c.end(); i != last; ) { +for (auto i = c.begin(); i != c.end(); ) { if (pred(*i)) { i = c.erase(i); } else {