Mark string_view's constructor from (ptr,len) as noexcept (an extension). Update the tests to check this (and other noexcept bits

llvm-svn: 316456
This commit is contained in:
Marshall Clow 2017-10-24 16:30:06 +00:00
parent 9c8f853ca9
commit ac2b3e3a7a
5 changed files with 16 additions and 4 deletions

View File

@ -216,7 +216,7 @@ public:
basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view(const _CharT* __s, size_type __len) basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
: __data(__s), __size(__len) : __data(__s), __size(__len)
{ {
// #if _LIBCPP_STD_VER > 11 // #if _LIBCPP_STD_VER > 11

View File

@ -21,6 +21,8 @@ template<typename T>
void test () { void test () {
#if TEST_STD_VER > 11 #if TEST_STD_VER > 11
{ {
ASSERT_NOEXCEPT(T());
constexpr T sv1; constexpr T sv1;
static_assert ( sv1.size() == 0, "" ); static_assert ( sv1.size() == 0, "" );
static_assert ( sv1.empty(), ""); static_assert ( sv1.empty(), "");

View File

@ -30,7 +30,11 @@ size_t StrLen ( const CharT *s ) {
template<typename CharT> template<typename CharT>
void test ( const CharT *s ) { void test ( const CharT *s ) {
std::basic_string_view<CharT> sv1 ( s ); typedef std::basic_string_view<CharT> SV;
// I'd love to do this, but it would require traits::length() to be noexcept
// LIBCPP_ASSERT_NOEXCEPT(SV(s));
SV sv1 ( s );
assert ( sv1.size() == StrLen( s )); assert ( sv1.size() == StrLen( s ));
assert ( sv1.data() == s ); assert ( sv1.data() == s );
} }

View File

@ -23,7 +23,10 @@
template<typename CharT> template<typename CharT>
void test ( const CharT *s, size_t sz ) { void test ( const CharT *s, size_t sz ) {
{ {
std::basic_string_view<CharT> sv1 ( s, sz ); typedef std::basic_string_view<CharT> SV;
LIBCPP_ASSERT_NOEXCEPT(SV(s, sz));
SV sv1 ( s, sz );
assert ( sv1.size() == sz ); assert ( sv1.size() == sz );
assert ( sv1.data() == s ); assert ( sv1.data() == s );
} }

View File

@ -24,7 +24,10 @@ struct dummy_char_traits : public std::char_traits<char> {};
template<typename CharT, typename Traits> template<typename CharT, typename Traits>
void test ( const std::basic_string<CharT, Traits> &str ) { void test ( const std::basic_string<CharT, Traits> &str ) {
std::basic_string_view<CharT, Traits> sv1 ( str ); typedef std::basic_string_view<CharT, Traits> SV;
ASSERT_NOEXCEPT(SV(str));
SV sv1 ( str );
assert ( sv1.size() == str.size()); assert ( sv1.size() == str.size());
assert ( sv1.data() == str.data()); assert ( sv1.data() == str.data());
} }