`<string>`: `basic_string`'s erasing operations don't orphan iterators
I maintainer di solito rispondono entro 2 giorni
@frederick-vs-ja ci sta già lavorando.
Dal 23/11/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
Start by comparing basic_string iterator handling for pop_back, erase, and clear with vector's behavior in the MSVC STL. Use the command-line test case with _ITERATOR_DEBUG_LEVEL == 2 and -std:c++20 -D_DEBUG to check the reported gap. Done means erasing operations diagnose invalidated iterators in both compile-time and run-time debug checks, as described.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
As discovered by Copilot in https://github.com/microsoft/STL/pull/6500#discussion_r4377205703, MSVC STL's basic_string seems to lack iterator orphaning in erasing operations (pop_back, erase, and clear).
It's unclear to me whether this is by design. At least the status of basic_string is inconsistent with vector.
Command-line test case
#include <cassert>
#include <string>
#include <vector>
#if _ITERATOR_DEBUG_LEVEL != 2
#error
#endif // _ITERATOR_DEBUG_LEVEL != 2
constexpr bool test_string() {
auto s = std::string{"The quick brown fox jumps over the lazy dog"};
auto it = s.cbegin();
auto jt = s.cbegin() + 10;
s.erase(it + 5);
return it == jt - 10;
}
static_assert(test_string()); // not diagnosed when _ITERATOR_DEBUG_LEVEL == 2
constexpr bool test_vector() {
auto v = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
auto it = v.cbegin();
auto jt = v.cbegin() + 10;
v.erase(it + 5);
return it == jt - 10;
}
static_assert(test_vector()); // diagnosed when _ITERATOR_DEBUG_LEVEL == 2
Godbolt link, using -std:c++20 -D_DEBUG.
Expected behavior
test_string() also fails in debug modes, in both compile time and run time.
STL version
Latest https://github.com/microsoft/STL/commit/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0.
(For the online example, probably https://github.com/microsoft/STL/commit/edd1486e5fe753616b6fd3695da96f352b4092d2.)
Additional context
- Lingua principale
- C++
- Stelle
- 11.2k
- Fork
- 1.7k
- Merge medio
- 4g 4h
- PR unite (30g)
- 14
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/STL
-
LWG
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
generator LWG
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
LWG
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
`<__msvc_math.hpp>`: `_USE_MATH_DEFINES` is ignored after the first `<math.h>` include under `/Zc:cmath`Forse già presa @tiagomacarios l’ha presa 10 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di microsoft/STL
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
ClickHouse/clickhouse-odbc#680 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ionut-mihalache/aqua#31 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
needs-kind
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
villagesql/villagesql-server#1702 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
microsoft/vcpkg-tool#2191 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno