[PATCH] D17053: [libcxx]: vector: Use < instead of != to improve failure mode
Louis Dionne via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 7 05:48:28 PDT 2020
ldionne added a comment.
In D17053#2315384 <https://reviews.llvm.org/D17053#2315384>, @dexonsmith wrote:
> In D17053#632700 <https://reviews.llvm.org/D17053#632700>, @EricWF wrote:
>
>> Maybe if we want to improve the failure mode we can add a `_LIBCPP_ASSERT(__new_last <= __end, "invalid range")`?
>
> I suspect this assertion would get optimized out, since if `__new_last > __end` it's undefined behaviour to compare them. Whereas the loop condition won't get optimized away.
>
> @ldionne, pointing you at this in case you have an idea (maybe specializing for raw pointers?), but I'm not planning to move this forward.
Thanks for the heads up. We already have `_LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");` in `vector::pop_back()`, but it doesn't trigger because assertions in libc++ are tied to whether the debug mode is enabled, and by default, it's not enabled at all. I believe that fixing this instead is the right way to go, since we'll get this improvement but also several additional assertions that are already in place in libc++. It is on my roadmap to improve that situation.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D17053/new/
https://reviews.llvm.org/D17053
More information about the cfe-commits
mailing list