Skip to content

Commit e4d4a68

Browse files
committed
Fix MSVC warnings in tests
MSVC complains about narrowing conversions and unreferences parameters. This makes all tests almost level 4 warning clean on MSVC 14.
1 parent 7d8a063 commit e4d4a68

7 files changed

+25
-25
lines changed

test/copy_if_test1.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
namespace ba = boost::algorithm;
2929
// namespace ba = boost;
3030

31-
BOOST_CXX14_CONSTEXPR bool is_true ( int v ) { return true; }
32-
BOOST_CXX14_CONSTEXPR bool is_false ( int v ) { return false; }
31+
BOOST_CXX14_CONSTEXPR bool is_true ( int ) { return true; }
32+
BOOST_CXX14_CONSTEXPR bool is_false ( int ) { return false; }
3333
BOOST_CXX14_CONSTEXPR bool is_even ( int v ) { return v % 2 == 0; }
3434
BOOST_CXX14_CONSTEXPR bool is_odd ( int v ) { return v % 2 == 1; }
3535
BOOST_CXX14_CONSTEXPR bool is_zero ( int v ) { return v == 0; }

test/hex_test4.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void test_short_input1 () {
2525
std::string s;
2626

2727
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
28-
catch ( const std::exception &ex ) { return; }
28+
catch ( const std::exception & ) { return; }
2929
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_short_input1" );
3030
BOOST_CHECK ( false );
3131
}
@@ -34,7 +34,7 @@ void test_short_input2 () {
3434
std::string s;
3535

3636
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
37-
catch ( const ba::hex_decode_error &ex ) { return; }
37+
catch ( const ba::hex_decode_error & ) { return; }
3838
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_short_input2" );
3939
BOOST_CHECK ( false );
4040
}
@@ -43,7 +43,7 @@ void test_short_input3 () {
4343
std::string s;
4444

4545
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
46-
catch ( const ba::not_enough_input &ex ) { return; }
46+
catch ( const ba::not_enough_input & ) { return; }
4747
BOOST_TEST_MESSAGE ( "Failed to catch ba::not_enough_input in test_short_input3" );
4848
BOOST_CHECK ( false );
4949
}
@@ -53,8 +53,8 @@ void test_short_input4 () {
5353
std::string s;
5454

5555
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
56-
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
57-
catch ( const ba::not_enough_input &ex ) { return; }
56+
catch ( const ba::non_hex_input & ) { BOOST_CHECK ( false ); }
57+
catch ( const ba::not_enough_input & ) { return; }
5858
catch ( ... ) { BOOST_CHECK ( false ); }
5959
BOOST_CHECK ( false );
6060
}
@@ -64,8 +64,8 @@ void test_short_input5 () {
6464
std::string s;
6565

6666
try { ba::unhex ( "A", std::back_inserter(s)); }
67-
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
68-
catch ( const ba::not_enough_input &ex ) { return; }
67+
catch ( const ba::non_hex_input & ) { BOOST_CHECK ( false ); }
68+
catch ( const ba::not_enough_input & ) { return; }
6969
catch ( ... ) { BOOST_CHECK ( false ); }
7070
BOOST_CHECK ( false );
7171
}
@@ -125,8 +125,8 @@ void test_nonhex_input4 () {
125125
std::string s;
126126

127127
try { ba::unhex ( "P1234FA1234", std::back_inserter(s)); }
128-
catch ( const ba::not_enough_input &ex ) { BOOST_CHECK ( false ); }
129-
catch ( const ba::non_hex_input &ex ) { return; }
128+
catch ( const ba::not_enough_input & ) { BOOST_CHECK ( false ); }
129+
catch ( const ba::non_hex_input & ) { return; }
130130
catch ( ... ) { BOOST_CHECK ( false ); }
131131
BOOST_CHECK ( false );
132132
}

test/is_permutation_test1.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void test_sequence1 () {
112112
std::vector<int> v, v1;
113113

114114
v.clear ();
115-
for ( std::size_t i = 5; i < 15; ++i )
115+
for ( int i = 5; i < 15; ++i )
116116
v.push_back ( i );
117117
v1 = v;
118118
BOOST_CHECK ( ba::is_permutation ( v.begin (), v.end (), v.begin ())); // better be a permutation of itself!

test/search_test1.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace {
3232

3333
// Check using iterators
3434
template<typename Container>
35-
void check_one_iter ( const Container &haystack, const std::string &needle, int expected ) {
35+
void check_one_iter ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
3636
typedef typename Container::const_iterator iter_type;
3737
typedef typename std::pair<iter_type, iter_type> ret_type;
3838
typedef std::string::const_iterator pattern_type;
@@ -53,7 +53,7 @@ namespace {
5353
// iter_type it1r = ret1r.first;
5454
// iter_type it2 = ret2.first;
5555
// iter_type it3 = ret3.first;
56-
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
56+
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
5757

5858
std::cout << "(Iterators) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
5959
try {
@@ -97,7 +97,7 @@ namespace {
9797
// Check using pointers
9898
// We're assuming that the container implements contiguous storage here.
9999
template<typename Container>
100-
void check_one_pointer ( const Container &haystack, const std::string &needle, int expected ) {
100+
void check_one_pointer ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
101101
typedef const typename Container::value_type *ptr_type;
102102
typedef typename std::pair<ptr_type, ptr_type> ret_type;
103103

@@ -110,7 +110,7 @@ namespace {
110110
ret_type ret1 = ba::boyer_moore_search (hBeg, hEnd, nBeg, nEnd);
111111
ret_type ret2 = ba::boyer_moore_horspool_search (hBeg, hEnd, nBeg, nEnd);
112112
ret_type ret3 = ba::knuth_morris_pratt_search (hBeg, hEnd, nBeg, nEnd);
113-
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
113+
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
114114

115115
std::cout << "(Pointers) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
116116
try {
@@ -147,7 +147,7 @@ namespace {
147147

148148
// Check using objects
149149
template<typename Container>
150-
void check_one_object ( const Container &haystack, const std::string &needle, int expected ) {
150+
void check_one_object ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
151151
typedef typename Container::const_iterator iter_type;
152152
typedef typename std::pair<iter_type, iter_type> ret_type;
153153
typedef std::string::const_iterator pattern_type;
@@ -169,7 +169,7 @@ namespace {
169169
ret_type retr1r = bm_r (haystack);
170170
ret_type ret2 = bmh (hBeg, hEnd);
171171
ret_type ret3 = kmp (hBeg, hEnd);
172-
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
172+
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
173173

174174
std::cout << "(Objects) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
175175
try {
@@ -224,7 +224,7 @@ namespace {
224224

225225

226226
template<typename Container>
227-
void check_one ( const Container &haystack, const std::string &needle, int expected ) {
227+
void check_one ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
228228
check_one_iter ( haystack, needle, expected );
229229
check_one_pointer ( haystack, needle, expected );
230230
check_one_object ( haystack, needle, expected );

test/search_test2.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace {
8585
std::cout << std::endl;
8686
}
8787

88-
void check_one ( const vec &haystack, const vec &needle, int expected ) {
88+
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
8989
std::size_t i;
9090
std::clock_t sTime;
9191
unsigned long stdDiff;
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( test_main )
147147
std::cout << "---- Middle -----" << std::endl;
148148
check_one ( c1, p1f, -2 ); // Don't know answer
149149
std::cout << "------ End ------" << std::endl;
150-
check_one ( c1, p1e, c1.size() - p1e.size ());
150+
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
151151
std::cout << "--- Not found ---" << std::endl;
152152
check_one ( c1, p1n, -1 ); // Not found
153153
}

test/search_test3.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace {
8585
std::cout << std::endl;
8686
}
8787

88-
void check_one ( const vec &haystack, const vec &needle, int expected ) {
88+
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
8989
std::size_t i;
9090
std::clock_t sTime;
9191
unsigned long stdDiff;
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( test_main )
147147
std::cout << "---- Middle -----" << std::endl;
148148
check_one ( c1, p1f, -2 ); // Don't know answer
149149
std::cout << "------ End ------" << std::endl;
150-
check_one ( c1, p1e, c1.size() - p1e.size ());
150+
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
151151
std::cout << "--- Not found ---" << std::endl;
152152
check_one ( c1, p1n, -1 ); // Not found
153153
}

test/search_test4.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace {
6262
return retVal;
6363
}
6464

65-
void check_one ( const vec &haystack, const vec &needle, int expected ) {
65+
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
6666

6767
std::pair<vec::const_iterator, vec::const_iterator> res;
6868
std::pair<vec::const_iterator, vec::const_iterator> exp; // the expected result
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE( test_main )
117117
std::cout << "---- Middle -----" << std::endl;
118118
check_one ( c1, p1f, -2 ); // Don't know answer
119119
std::cout << "------ End ------" << std::endl;
120-
check_one ( c1, p1e, c1.size() - p1e.size ());
120+
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
121121
std::cout << "--- Not found ---" << std::endl;
122122
check_one ( c1, p1n, -1 ); // Not found
123123
}

0 commit comments

Comments
 (0)