[libcxx-commits] [libcxx] [libc++] Remove assertions from <string_view> that are unreachable (PR #148598)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 14 02:55:01 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/148598
When assertions are enabled it is impossible to construct a `string_view` which contains a null pointer and a non-zero size, so assertions where we check for that on an already constructed `string_view` are unreachable.
>From b6c6104bd7f2ffcf1bd16322e05f4e2220cfc2f0 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 14 Jul 2025 11:53:42 +0200
Subject: [PATCH] [libc++] Remove assertions from <string_view> that are
unreachable
---
libcxx/include/string_view | 8 --------
1 file changed, 8 deletions(-)
diff --git a/libcxx/include/string_view b/libcxx/include/string_view
index 861187c0640e1..4a85c73733023 100644
--- a/libcxx/include/string_view
+++ b/libcxx/include/string_view
@@ -500,7 +500,6 @@ public:
// find
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
}
@@ -524,7 +523,6 @@ public:
// rfind
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
}
@@ -549,7 +547,6 @@ public:
// find_first_of
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
data(), size(), __s.data(), __pos, __s.size());
}
@@ -575,7 +572,6 @@ public:
// find_last_of
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
find_last_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
data(), size(), __s.data(), __pos, __s.size());
}
@@ -601,8 +597,6 @@ public:
// find_first_not_of
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
find_first_not_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(
- __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
data(), size(), __s.data(), __pos, __s.size());
}
@@ -628,8 +622,6 @@ public:
// find_last_not_of
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
find_last_not_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
- _LIBCPP_ASSERT_NON_NULL(
- __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
data(), size(), __s.data(), __pos, __s.size());
}
More information about the libcxx-commits
mailing list