[libcxx-commits] [PATCH] D121407: Allow temporary string_view((const char*)nullptr) while cleanup occurs.

Eric Fiselier via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 10 13:12:43 PST 2022


EricWF created this revision.
EricWF added a reviewer: ldionne.
EricWF added a project: libc++.
Herald added a project: All.
EricWF requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Google is working to clean up a local patch to libc++ that allows
string_view to be constructed from null pointers. In order to do this we
need to intercept the call to char_traits::length. This temporary change
allows google to live at head with libc++ while it cleans up
 non-conforming code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121407

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


Index: libcxx/include/string_view
===================================================================
--- libcxx/include/string_view
+++ libcxx/include/string_view
@@ -317,7 +317,7 @@
 
     _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
     basic_string_view(const _CharT* __s)
-        : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
+        : __data(__s), __size(_LIBCPP_CHAR_TRAITS_LENGTH_HOOK(_Traits, __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 <>
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -1444,6 +1444,13 @@
 #  define _LIBCPP_PACKED_BYTE_FOR_AIX_END  /* empty */
 #endif
 
+// Used to allow Google to transition to std::string_view while cleaning up
+// code that constructs it from `nullptr` -- which is undefined.
+// TODO(EricWF) Remove me!
+#ifndef _LIBCPP_CHAR_TRAITS_LENGTH_HOOK
+#  define _LIBCPP_CHAR_TRAITS_LENGTH_HOOK(_TraitsType, __str) _TraitType::length(__str)
+#endif
+
 #endif // __cplusplus
 
 #endif // _LIBCPP_CONFIG


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121407.414475.patch
Type: text/x-patch
Size: 1851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220310/3fb0a85b/attachment.bin>


More information about the libcxx-commits mailing list