[libcxx-commits] [libcxx] [libc++] Add a few _LIBCPP_ASSERT_INTERNALs to make sure internal invariants are kept (PR #114575)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 1 12:32:58 PDT 2024


================
@@ -57,6 +57,12 @@ __is_pointer_in_range(const _Tp* __begin, const _Tp* __end, const _Up* __ptr) {
          reinterpret_cast<const char*>(__ptr) < reinterpret_cast<const char*>(__end);
 }
 
+template <class _Tp, class _Up>
+_LIBCPP_CONSTEXPR_SINCE_CXX14 bool __is_overlapping_range(const _Tp* __begin, const _Tp* __end, const _Up* __begin2) {
+  return std::__is_pointer_in_range(__begin, __end, __begin2) ||
+         std::__is_pointer_in_range(__begin2, __begin2 + (__end - __begin), __begin);
+}
----------------
ldionne wrote:

```suggestion
  auto __size = __end - __begin;
  auto __end2 = __begin2 + __size;
  return std::__is_pointer_in_range(__begin, __end, __begin2) ||
         std::__is_pointer_in_range(__begin2, __end2, __begin);
}
```

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


More information about the libcxx-commits mailing list