[libcxx-commits] [libcxx] [libc++][test] Fixes constexpr nasty_char_traits. (PR #90981)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 7 08:53:47 PDT 2024


================
@@ -16,6 +16,30 @@
 
 #include "test_macros.h"
 
+// Tests whether the range [p1, p1 + n) overlaps with the range [p2, p2 + n).
+//
+// precondition The ranges [p1, p1 + n) and [p2, p2 + n) are valid ranges.
+//
+// Typically the pointers are compared with less than. This is not allowed when
+// the pointers belong to different ranges. This is UB. Typically, this is
+// benign at run-time, however since UB is not allowed during constant
+// evaluation this does not compile. This function does the validation without
+// UB.
+//
+// When the ranges overlap the ranges can be copied from the beginning to the
+// end. Otherwise they need to be copied from the end to the beginning.
+template <class Traits>
+TEST_CONSTEXPR_CXX14 bool is_overlapping_range(Traits* p1, const Traits* p2, std::size_t n) {
----------------
ldionne wrote:

```suggestion
template <class CharT>
TEST_CONSTEXPR_CXX14 bool is_overlapping_range(const CharT* p1, const CharT* p2, std::size_t n) {
```

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


More information about the libcxx-commits mailing list