[libcxx-commits] [libcxx] [libc++][hardening] Use bounded iterators in std::vector and std::string (PR #78929)
David Benjamin via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 24 06:59:42 PST 2024
davidben wrote:
> First, I opted not to size it against the capacity. https://eel.is/c++draft/string.require#4 says iterators are invalided on an non-const operation.
Ran into an interesting case. While this PR doesn't trip it, I looked at adding iterator compatibility checks for https://github.com/llvm/llvm-project/issues/78771#issuecomment-1902999181 and that tripped one of libc++'s existing `std::string` tests:
This test is only valid if we take the position that iterators remain valid when appending up to capacity:
https://github.com/llvm/llvm-project/blob/380ac53dfa05792c6f9fd0a4aba542f8c7e5e17c/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp#L31-L32
However, if I'm reading the spec correctly, I don't think that is guaranteed. Yet this test is under "std" and not "libcxx". Thoughts? Should we bound the string iterator to the capacity too?
https://github.com/llvm/llvm-project/pull/78929
More information about the libcxx-commits
mailing list