Avoid -Wsign-conversion warnings in string_view.hpp. Fixes #170.

This commit is contained in:
Peter Dimov
2024-04-11 04:09:29 +03:00
parent 8b31acf9a4
commit 03040c7f5c
6 changed files with 69 additions and 51 deletions

View File

@@ -74,7 +74,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_first_of( Ch const* p_
for( std::size_t j = 0; j < n; ++j )
{
UCh ch = s[ j ];
UCh ch = static_cast<UCh>( s[ j ] );
if( ch >= 0 && ch < 256 )
{
@@ -91,7 +91,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_first_of( Ch const* p_
{
for( std::size_t i = pos; i < n_; ++i )
{
UCh ch = p_[ i ];
UCh ch = static_cast<UCh>( p_[ i ] );
if( ch >= 0 && ch < 256 && table[ ch ] ) return i;
}
}
@@ -129,7 +129,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_last_of( Ch const* p_,
for( std::size_t j = 0; j < n; ++j )
{
UCh ch = s[ j ];
UCh ch = static_cast<UCh>( s[ j ] );
if( ch >= 0 && ch < 256 )
{
@@ -150,7 +150,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_last_of( Ch const* p_,
{
do
{
UCh ch = p_[ i ];
UCh ch = static_cast<UCh>( p_[ i ] );
if( ch >= 0 && ch < 256 && table[ ch ] ) return i;
@@ -199,7 +199,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_first_not_of( Ch const
for( std::size_t j = 0; j < n; ++j )
{
UCh ch = s[ j ];
UCh ch = static_cast<UCh>( s[ j ] );
if( ch >= 0 && ch < 256 )
{
@@ -216,7 +216,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_first_not_of( Ch const
{
for( std::size_t i = pos; i < n_; ++i )
{
UCh ch = p_[ i ];
UCh ch = static_cast<UCh>( p_[ i ] );
if( !( ch >= 0 && ch < 256 && table[ ch ] ) ) return i;
}
}
@@ -262,7 +262,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_last_not_of( Ch const*
for( std::size_t j = 0; j < n; ++j )
{
UCh ch = s[ j ];
UCh ch = static_cast<UCh>( s[ j ] );
if( ch >= 0 && ch < 256 )
{
@@ -283,7 +283,7 @@ template<class Ch> BOOST_CXX14_CONSTEXPR std::size_t find_last_not_of( Ch const*
{
do
{
UCh ch = p_[ i ];
UCh ch = static_cast<UCh>( p_[ i ] );
if( !( ch >= 0 && ch < 256 && table[ ch ] ) ) return i;
@@ -381,7 +381,7 @@ public:
}
template<class End> BOOST_CXX14_CONSTEXPR basic_string_view( Ch const* first, End last,
typename boost::enable_if<boost::core::detail::is_same<End, Ch const*> >::type* = 0 ) BOOST_NOEXCEPT: p_( first ), n_( last - first )
typename boost::enable_if<boost::core::detail::is_same<End, Ch const*> >::type* = 0 ) BOOST_NOEXCEPT: p_( first ), n_( static_cast<size_type>( last - first ) )
{
BOOST_ASSERT( last - first >= 0 );
}
@@ -681,7 +681,7 @@ public:
Ch const* r = traits_type::find( data() + pos, size() - pos, c );
return r? r - data(): npos;
return r? static_cast<size_type>( r - data() ): npos;
}
BOOST_CXX14_CONSTEXPR size_type find( Ch const* s, size_type pos, size_type n ) const BOOST_NOEXCEPT
@@ -696,11 +696,11 @@ public:
for( ;; )
{
p = traits_type::find( p, last - p, s[0] );
p = traits_type::find( p, static_cast<size_type>( last - p ), s[0] );
if( p == 0 ) break;
if( traits_type::compare( p + 1, s + 1, n - 1 ) == 0 ) return p - data();
if( traits_type::compare( p + 1, s + 1, n - 1 ) == 0 ) return static_cast<size_type>( p - data() );
++p;
}
@@ -1193,7 +1193,7 @@ public:
template<class Ch> std::basic_ostream<Ch>& operator<<( std::basic_ostream<Ch>& os, basic_string_view<Ch> str )
{
Ch const* p = str.data();
std::streamsize n = str.size();
std::streamsize n = static_cast<std::streamsize>( str.size() );
std::streamsize m = os.width();

View File

@@ -337,33 +337,51 @@ run type_name_test.cpp ;
run snprintf_test.cpp ;
run sv_types_test.cpp ;
run sv_construct_test.cpp ;
run sv_iteration_test.cpp ;
run sv_element_access_test.cpp ;
run sv_modifiers_test.cpp ;
run sv_copy_test.cpp ;
run sv_substr_test.cpp ;
run sv_compare_test.cpp ;
run sv_starts_with_test.cpp ;
run sv_ends_with_test.cpp ;
run sv_find_test.cpp ;
run sv_rfind_test.cpp ;
run sv_types_test.cpp
: : : $(pedantic-errors) ;
run sv_construct_test.cpp
: : : $(pedantic-errors) ;
run sv_iteration_test.cpp
: : : $(pedantic-errors) ;
run sv_element_access_test.cpp
: : : $(pedantic-errors) ;
run sv_modifiers_test.cpp
: : : $(pedantic-errors) ;
run sv_copy_test.cpp
: : : $(pedantic-errors) ;
run sv_substr_test.cpp
: : : $(pedantic-errors) ;
run sv_compare_test.cpp
: : : $(pedantic-errors) ;
run sv_starts_with_test.cpp
: : : $(pedantic-errors) ;
run sv_ends_with_test.cpp
: : : $(pedantic-errors) ;
run sv_find_test.cpp
: : : $(pedantic-errors) ;
run sv_rfind_test.cpp
: : : $(pedantic-errors) ;
run sv_find_first_of_test.cpp
: : : <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
: : : $(pedantic-errors) <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
run sv_find_last_of_test.cpp
: : : <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
: : : $(pedantic-errors) <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
run sv_find_first_not_of_test.cpp
: : : <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
: : : $(pedantic-errors) <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
run sv_find_last_not_of_test.cpp
: : : <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
run sv_contains_test.cpp ;
run sv_eq_test.cpp ;
run sv_lt_test.cpp ;
run sv_stream_insert_test.cpp ;
run sv_conversion_test.cpp ;
: : : $(pedantic-errors) <toolset>gcc-4.4:<cxxflags>-Wno-type-limits ;
run sv_contains_test.cpp
: : : $(pedantic-errors) ;
run sv_eq_test.cpp
: : : $(pedantic-errors) ;
run sv_lt_test.cpp
: : : $(pedantic-errors) ;
run sv_stream_insert_test.cpp
: : : $(pedantic-errors) ;
run sv_conversion_test.cpp
: : : $(pedantic-errors) ;
run sv_conversion_test2.cpp : ;
run sv_common_reference_test.cpp ;
run sv_common_reference_test.cpp
: : : $(pedantic-errors) ;
compile sv_common_reference_test2.cpp ;
compile sv_windows_h_test.cpp ;
compile-fail sv_nullptr_fail.cpp

View File

@@ -494,7 +494,7 @@ int main()
for( int i = 0; i < 256; ++i )
{
str[ i ] = static_cast< unsigned char >( i );
str[ i ] = static_cast<char>( static_cast< unsigned char >( i ) );
}
boost::core::string_view sv( str, 256 );
@@ -503,7 +503,7 @@ int main()
std::string str2( sv.data(), sv.size() );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::string str3( str2 );
@@ -514,7 +514,7 @@ int main()
std::reverse( str, str + 256 );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::string str3( str2 );
@@ -538,7 +538,7 @@ int main()
std::wstring str2( sv.data(), sv.size() );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::wstring str3( str2 );
@@ -549,7 +549,7 @@ int main()
std::reverse( str, str + 256 );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::wstring str3( str2 );

View File

@@ -426,14 +426,14 @@ int main()
for( int i = 0; i < 256; ++i )
{
str[ i ] = static_cast< unsigned char >( i );
str[ i ] = static_cast<char>( static_cast< unsigned char >( i ) );
}
boost::core::string_view sv( str, 256 );
for( int i = 0; i < 256; ++i )
{
std::string needle( 12, static_cast< unsigned char >( i ) );
std::string needle( 12, static_cast<char>( static_cast< unsigned char >( i ) ) );
BOOST_TEST_EQ( sv.find_first_of( needle ), i );
}
@@ -441,7 +441,7 @@ int main()
for( int i = 0; i < 256; ++i )
{
std::string needle( 12, static_cast< unsigned char >( i ) );
std::string needle( 12, static_cast<char>( static_cast< unsigned char >( i ) ) );
BOOST_TEST_EQ( sv.find_first_of( needle ), 255 - i );
}
}

View File

@@ -494,7 +494,7 @@ int main()
for( int i = 0; i < 256; ++i )
{
str[ i ] = static_cast< unsigned char >( i );
str[ i ] = static_cast<char>( static_cast< unsigned char >( i ) );
}
boost::core::string_view sv( str, 256 );
@@ -503,7 +503,7 @@ int main()
std::string str2( sv.data(), sv.size() );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::string str3( str2 );
@@ -514,7 +514,7 @@ int main()
std::reverse( str, str + 256 );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::string str3( str2 );
@@ -538,7 +538,7 @@ int main()
std::wstring str2( sv.data(), sv.size() );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::wstring str3( str2 );
@@ -549,7 +549,7 @@ int main()
std::reverse( str, str + 256 );
for( int i = 0; i < 256; ++i )
for( std::size_t i = 0; i < 256; ++i )
{
std::wstring str3( str2 );

View File

@@ -444,14 +444,14 @@ int main()
for( int i = 0; i < 256; ++i )
{
str[ i ] = static_cast< unsigned char >( i );
str[ i ] = static_cast<char>( static_cast< unsigned char >( i ) );
}
boost::core::string_view sv( str, 256 );
for( int i = 0; i < 256; ++i )
{
std::string needle( 12, static_cast< unsigned char >( i ) );
std::string needle( 12, static_cast<char>( static_cast< unsigned char >( i ) ) );
BOOST_TEST_EQ( sv.find_last_of( needle ), i );
}
@@ -459,7 +459,7 @@ int main()
for( int i = 0; i < 256; ++i )
{
std::string needle( 12, static_cast< unsigned char >( i ) );
std::string needle( 12, static_cast<char>( static_cast< unsigned char >( i ) ) );
BOOST_TEST_EQ( sv.find_last_of( needle ), 255 - i );
}
}