Replaced checking in string_view::remove_suffix/remove_prefix by _LIBCPP_ASSERT, since this is technically undefined behavior. Fixes PR#21496

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@221717 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2014-11-11 22:07:10 +00:00
parent 3f5579f0b2
commit 1cf810b81b
3 changed files with 6 additions and 14 deletions

View File

@ -313,8 +313,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void remove_prefix(size_type __n) _NOEXCEPT
{
if (__n > __size)
__n = __size;
_LIBCPP_ASSERT(n <= size(), "remove_prefix() can't remove more than size()");
__data += __n;
__size -= __n;
}
@ -322,8 +321,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void remove_suffix(size_type __n) _NOEXCEPT
{
if (__n > __size)
__n = __size;
_LIBCPP_ASSERT(n <= size(), "remove_suffix() can't remove more than size()");
__size -= __n;
}

View File

@ -28,13 +28,11 @@ void test ( const CharT *s, size_t len ) {
sv1.remove_prefix ( 1 );
assert ( sv1.size() == (len - 1));
assert ( sv1.data() == (s + 1));
sv1.remove_prefix ( len - 1 );
}
sv1.remove_prefix ( len - 1 );
assert ( sv1.size() == 0 );
SV sv2 ( s );
sv2.remove_prefix ( len << 1 );
sv1.remove_prefix ( 0 );
assert ( sv1.size() == 0 );
}
}
@ -72,7 +70,6 @@ int main () {
static_assert ( test_ce ( 5, 0 ) == 5, "" );
static_assert ( test_ce ( 5, 1 ) == 4, "" );
static_assert ( test_ce ( 5, 5 ) == 0, "" );
static_assert ( test_ce ( 5, 9 ) == 0, "" );
static_assert ( test_ce ( 9, 3 ) == 6, "" );
}
#endif

View File

@ -27,13 +27,11 @@ void test ( const CharT *s, size_t len ) {
sv1.remove_suffix ( 1 );
assert ( sv1.size() == (len - 1));
assert ( sv1.data() == s);
sv1.remove_suffix ( len - 1 );
}
sv1.remove_suffix ( len - 1 );
assert ( sv1.size() == 0 );
SV sv2 ( s );
sv2.remove_suffix ( len << 1 );
sv1.remove_suffix ( 0 );
assert ( sv1.size() == 0 );
}
@ -72,7 +70,6 @@ int main () {
static_assert ( test_ce ( 5, 0 ) == 5, "" );
static_assert ( test_ce ( 5, 1 ) == 4, "" );
static_assert ( test_ce ( 5, 5 ) == 0, "" );
static_assert ( test_ce ( 5, 9 ) == 0, "" );
static_assert ( test_ce ( 9, 3 ) == 6, "" );
}
#endif