[libcxx-commits] [libcxx] [libc++][hardening] Categorize more assertions. (PR #75918)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 20 14:00:51 PST 2023


================
@@ -36,7 +36,8 @@ __pop_heap(_RandomAccessIterator __first,
            _RandomAccessIterator __last,
            _Compare& __comp,
            typename iterator_traits<_RandomAccessIterator>::difference_type __len) {
-  _LIBCPP_ASSERT_UNCATEGORIZED(__len > 0, "The heap given to pop_heap must be non-empty");
+  // Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op.
----------------
ldionne wrote:

I would consider taking advantage of this precondition and removing `if (__len > 1)`, but then bumping this assertion to a valid-range (or similar) assertion. Thoughts? If we opt to do this, it would be as a separate change.

https://github.com/llvm/llvm-project/pull/75918


More information about the libcxx-commits mailing list