Skip to content

Commit 611469c

Browse files
committed
[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
1 parent 237df15 commit 611469c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

libcxx/include/__string

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,6 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
559559
}
560560
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
561561

562-
template <class _Traits>
563-
_LIBCPP_INLINE_VISIBILITY
564-
_LIBCPP_CONSTEXPR
565-
inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
566-
#if _LIBCPP_DEBUG_LEVEL >= 1
567-
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);
568-
#else
569-
return _Traits::length(__s);
570-
#endif
571-
}
572-
573562
#ifndef _LIBCPP_HAS_NO_CHAR8_T
574563

575564
template <>

libcxx/include/string_view

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ typedef basic_string_view<char32_t> u32string_view;
235235
typedef basic_string_view<wchar_t> wstring_view;
236236
#endif
237237

238+
// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
239+
// string_view constructors. This can be refactored when this exact form isn't needed anymore.
240+
template <class _Traits>
241+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
242+
inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
243+
// This needs to be a single statement for C++11 constexpr
244+
return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s);
245+
}
246+
238247
template<class _CharT, class _Traits>
239248
class
240249
_LIBCPP_PREFERRED_NAME(string_view)

0 commit comments

Comments
 (0)