[libcxx-commits] [libcxx] [libc++] Use __is_pointer_in_range for char_traits checks (PR #72643)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 17 10:04:23 PST 2023


================
@@ -142,14 +143,12 @@ struct _LIBCPP_DEPRECATED_("char_traits<T> for T not equal to char, wchar_t, cha
     _LIBCPP_INLINE_VISIBILITY
     static _LIBCPP_CONSTEXPR_SINCE_CXX20
     char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) {
-        if (!__libcpp_is_constant_evaluated()) {
-            _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(
-                __s2 < __s1 || __s2 >= __s1 + __n, "char_traits::copy overlapped range");
-        }
-        char_type* __r = __s1;
-        for (; __n; --__n, ++__s1, ++__s2)
-            assign(*__s1, *__s2);
-        return __r;
+      _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(
+          !std::__is_pointer_in_range(__s1, __s1 + __n, __s2), "char_traits::copy overlapped range");
----------------
ldionne wrote:

```suggestion
          !std::__is_pointer_in_range(__s1, __s1 + __n, __s2), "char_traits::copy: source and destination ranges overlap");
```

Everywhere

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


More information about the libcxx-commits mailing list