[libcxx-commits] [libcxx] 611469c - [libc++] Remove raw call to debug handler from __char_traits_length_checked

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 11 06:05:42 PST 2022


Author: Louis Dionne
Date: 2022-03-11T09:05:29-05:00
New Revision: 611469c5c5426c761cf02bd4bdde31890038b181

URL: https://github.com/llvm/llvm-project/commit/611469c5c5426c761cf02bd4bdde31890038b181
DIFF: https://github.com/llvm/llvm-project/commit/611469c5c5426c761cf02bd4bdde31890038b181.diff

LOG: [libc++] Remove raw call to debug handler from __char_traits_length_checked

As a fly-by fix, also move it closer to where it is needed, and add a
comment explaining the existence of this weird function.

Differential Revision: https://reviews.llvm.org/D121231

Added: 
    

Modified: 
    libcxx/include/__string
    libcxx/include/string_view

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__string b/libcxx/include/__string
index 973b6994a5c2f..f3471aed160fc 100644
--- a/libcxx/include/__string
+++ b/libcxx/include/__string
@@ -559,17 +559,6 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
 }
 #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 <>

diff  --git a/libcxx/include/string_view b/libcxx/include/string_view
index dd9239aaff655..5caa4c4678dd3 100644
--- a/libcxx/include/string_view
+++ b/libcxx/include/string_view
@@ -235,6 +235,15 @@ typedef basic_string_view<char32_t> u32string_view;
 typedef basic_string_view<wchar_t>  wstring_view;
 #endif
 
+// TODO: This is a workaround for some vendors to carry a downstream 
diff  to accept `nullptr` in
+//       string_view constructors. This can be refactored when this exact form isn't needed anymore.
+template <class _Traits>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
+inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
+  // This needs to be a single statement for C++11 constexpr
+  return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s);
+}
+
 template<class _CharT, class _Traits>
 class
     _LIBCPP_PREFERRED_NAME(string_view)


        


More information about the libcxx-commits mailing list