[libcxx-commits] [PATCH] D121231: [libc++] Remove raw call to debug handler from __char_traits_length_checked

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 8 14:52:41 PST 2022


ldionne updated this revision to Diff 413942.
ldionne added a comment.

Apply Arthur's excellent suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121231/new/

https://reviews.llvm.org/D121231

Files:
  libcxx/include/__string
  libcxx/include/string_view


Index: libcxx/include/string_view
===================================================================
--- libcxx/include/string_view
+++ libcxx/include/string_view
@@ -235,6 +235,13 @@
 typedef basic_string_view<wchar_t>  wstring_view;
 #endif
 
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
+inline _Tp* __assert_not_null(_Tp* __p) {
+  // This needs to be a single statement for C++11 constexpr
+  return _LIBCPP_ASSERT(__p != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), __p;
+}
+
 template<class _CharT, class _Traits>
 class
     _LIBCPP_PREFERRED_NAME(string_view)
@@ -317,7 +324,7 @@
 
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
     basic_string_view(const _CharT* __s)
-        : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
+        : __data(std::__assert_not_null(__s)), __size(_Traits::length(__s)) {}
 
 #if _LIBCPP_STD_VER > 20
     basic_string_view(nullptr_t) = delete;
Index: libcxx/include/__string
===================================================================
--- libcxx/include/__string
+++ libcxx/include/__string
@@ -559,17 +559,6 @@
 }
 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
-template <class _Traits>
-_LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR
-inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
-#if _LIBCPP_DEBUG_LEVEL >= 1
-  return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);
-#else
-  return _Traits::length(__s);
-#endif
-}
-
 #ifndef _LIBCPP_HAS_NO_CHAR8_T
 
 template <>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121231.413942.patch
Type: text/x-patch
Size: 1705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220308/688ad0e6/attachment.bin>


More information about the libcxx-commits mailing list