Skip to content

Commit e8b13bd

Browse files
authored
Enables -Wall and -Werror in CIs (#254)
Removed warnings in: * bench/echo_server_client.cpp (parameter shadowing) * include/boost/redis/adapter/detail/adapters.hpp (unused parameter) * include/boost/redis/connection.hpp (unused parameter) * include/boost/redis/resp3/impl/parser.ipp (signed to unsigned conversion) * test/test_conversions.cpp (signed to unsigned comparison) * test/test_issue_50.cpp (superfluous move) * test/test_low_level_sync_sans_io.cpp (signed to unsigned comparison)
1 parent c1c50e3 commit e8b13bd

File tree

11 files changed

+67
-56
lines changed

11 files changed

+67
-56
lines changed

benchmarks/cpp/asio/echo_server_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ auto example(boost::asio::ip::tcp::endpoint ep, std::string msg, int n) -> net::
2727
auto dbuffer = net::dynamic_buffer(buffer);
2828
for (int i = 0; i < n; ++i) {
2929
co_await net::async_write(socket, net::buffer(msg));
30-
auto n = co_await net::async_read_until(socket, dbuffer, "\n");
30+
auto bytes_read = co_await net::async_read_until(socket, dbuffer, "\n");
3131
//std::printf("> %s", buffer.data());
32-
dbuffer.consume(n);
32+
dbuffer.consume(bytes_read);
3333
}
3434

3535
//std::printf("Ok: %s", msg.data());

include/boost/redis/adapter/detail/adapters.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct converter<T, true> {
6666
template <>
6767
struct converter<bool, false> {
6868
template <class String>
69-
static void apply(bool& t, resp3::basic_node<String> const& node, system::error_code& ec)
69+
static void apply(bool& t, resp3::basic_node<String> const& node, system::error_code&)
7070
{
7171
t = *node.value.data() == 't';
7272
}

include/boost/redis/connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class run_op {
354354
system::error_code ec1 = {},
355355
system::error_code ec2 = {},
356356
system::error_code ec3 = {},
357-
system::error_code ec4 = {})
357+
system::error_code = {})
358358
{
359359
BOOST_ASIO_CORO_REENTER(coro_) for (;;)
360360
{

include/boost/redis/resp3/impl/parser.ipp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/assert.hpp>
1111

1212
#include <charconv>
13+
#include <cstddef>
1314
#include <limits>
1415

1516
namespace boost::redis::resp3 {
@@ -177,7 +178,7 @@ auto parser::consume_impl(type t, std::string_view elem, system::error_code& ec)
177178
case type::attribute:
178179
case type::map:
179180
{
180-
std::size_t l = -1;
181+
std::size_t l = static_cast<std::size_t>(-1);
181182
to_int(l, elem, ec);
182183
if (ec)
183184
return {};

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
add_library(boost_redis_project_options INTERFACE)
44
target_link_libraries(boost_redis_project_options INTERFACE boost_redis)
55
if (MSVC)
6-
target_compile_options(boost_redis_project_options INTERFACE /bigobj)
6+
# C4459: name hides outer scope variable is issued by Asio
7+
target_compile_options(boost_redis_project_options INTERFACE /bigobj /W4 /WX /wd4459)
78
target_compile_definitions(boost_redis_project_options INTERFACE _WIN32_WINNT=0x0601)
9+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
10+
target_compile_options(boost_redis_project_options INTERFACE -Wall -Wextra -Werror)
811
endif()
912

1013
add_library(boost_redis_src STATIC boost_redis.cpp)

test/Jamfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ local requirements =
3131
]
3232
[ ac.check-library /openssl//ssl : <library>/openssl//ssl/<link>shared : <build>no ]
3333
[ ac.check-library /openssl//crypto : <library>/openssl//crypto/<link>shared : <build>no ]
34-
<library>/boost/test//boost_unit_test_framework
34+
<library>/boost/test//boost_unit_test_framework/<warnings-as-errors>off
3535
;
3636

3737

test/test_conversions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ BOOST_AUTO_TEST_CASE(ints)
5757

5858
// Check
5959
BOOST_TEST(std::get<1>(resp).value() == 42);
60-
BOOST_TEST(std::get<2>(resp).value() == 42);
60+
BOOST_TEST(std::get<2>(resp).value() == 42u);
6161
BOOST_TEST(std::get<3>(resp).value() == 42);
62-
BOOST_TEST(std::get<4>(resp).value() == 42);
62+
BOOST_TEST(std::get<4>(resp).value() == 42u);
6363
BOOST_TEST(std::get<5>(resp).value() == 42);
64-
BOOST_TEST(std::get<6>(resp).value() == 42);
64+
BOOST_TEST(std::get<6>(resp).value() == 42u);
6565
BOOST_TEST(std::get<7>(resp).value() == 42);
66-
BOOST_TEST(std::get<8>(resp).value() == 42);
66+
BOOST_TEST(std::get<8>(resp).value() == 42u);
6767
BOOST_TEST(std::get<9>(resp).value() == 42);
68-
BOOST_TEST(std::get<10>(resp).value() == 42);
68+
BOOST_TEST(std::get<10>(resp).value() == 42u);
6969
}
7070

7171
BOOST_AUTO_TEST_CASE(bools)

test/test_issue_50.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ auto co_main(config) -> net::awaitable<void>
102102
BOOST_AUTO_TEST_CASE(issue_50)
103103
{
104104
net::io_context ioc;
105-
net::co_spawn(ioc, std::move(co_main({})), net::detached);
105+
net::co_spawn(ioc, co_main({}), net::detached);
106106
ioc.run();
107107
}
108108

test/test_low_level.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
* accompanying file LICENSE.txt)
55
*/
66

7-
#include <boost/redis/request.hpp>
8-
#include <boost/redis/response.hpp>
97
#include <boost/redis/adapter/adapt.hpp>
8+
#include <boost/redis/request.hpp>
109
#include <boost/redis/resp3/parser.hpp>
10+
#include <boost/redis/response.hpp>
1111

12-
#define BOOST_TEST_MODULE low level
12+
#define BOOST_TEST_MODULE low_level
1313
#include <boost/test/included/unit_test.hpp>
1414

1515
#include <map>
16-
#include <iostream>
1716
#include <optional>
1817
#include <sstream>
1918

2019
// TODO: Test with empty strings.
2120

22-
namespace std
23-
{
24-
auto operator==(boost::redis::ignore_t, boost::redis::ignore_t) noexcept {return true;}
25-
auto operator!=(boost::redis::ignore_t, boost::redis::ignore_t) noexcept {return false;}
26-
}
21+
namespace std {
22+
auto operator==(boost::redis::ignore_t, boost::redis::ignore_t) noexcept { return true; }
23+
auto operator!=(boost::redis::ignore_t, boost::redis::ignore_t) noexcept { return false; }
24+
} // namespace std
2725

2826
namespace redis = boost::redis;
2927
namespace resp3 = boost::redis::resp3;
@@ -56,12 +54,20 @@ using array_type = result<std::array<int, 3>>;
5654
using array_type2 = result<std::array<int, 1>>;
5755

5856
// Map
59-
using map_type = result<std::map<std::string, std::string>>;
60-
using mmap_type = result<std::multimap<std::string, std::string>>;
61-
using umap_type = result<std::unordered_map<std::string, std::string>>;
62-
using mumap_type = result<std::unordered_multimap<std::string, std::string>>;
57+
using map_type = result<std::map<std::string, std::string>>;
58+
using mmap_type = result<std::multimap<std::string, std::string>>;
59+
using umap_type = result<std::unordered_map<std::string, std::string>>;
60+
using mumap_type = result<std::unordered_multimap<std::string, std::string>>;
6361
using op_map_type = result<std::optional<std::map<std::string, std::string>>>;
64-
using tuple8_type = result<response<std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string>>;
62+
using tuple8_type = result<response<
63+
std::string,
64+
std::string,
65+
std::string,
66+
std::string,
67+
std::string,
68+
std::string,
69+
std::string,
70+
std::string>>;
6571

6672
// Null
6773
using op_type_01 = result<std::optional<bool>>;
@@ -85,7 +91,11 @@ struct expect {
8591
};
8692

8793
template <class Result>
88-
auto make_expected(std::string in, Result expected, error_code ec = {}, resp3::type error_type = resp3::type::invalid)
94+
auto make_expected(
95+
std::string in,
96+
Result expected,
97+
error_code ec = {},
98+
resp3::type error_type = resp3::type::invalid)
8999
{
90100
return expect<Result>{in, expected, ec, error_type};
91101
}
@@ -99,7 +109,7 @@ void test_sync(expect<Result> e)
99109
error_code ec;
100110
auto const res = parse(p, e.in, adapter, ec);
101111

102-
BOOST_TEST(res); // None of these tests need more data.
112+
BOOST_TEST(res); // None of these tests need more data.
103113

104114
if (ec) {
105115
BOOST_CHECK_EQUAL(ec, e.ec);
@@ -123,7 +133,7 @@ void test_sync2(expect<Result> e)
123133
error_code ec;
124134
auto const res = parse(p, e.in, adapter, ec);
125135

126-
BOOST_TEST(res); // None of these tests need more data.
136+
BOOST_TEST(res); // None of these tests need more data.
127137
BOOST_CHECK_EQUAL(ec, e.ec);
128138
}
129139

@@ -133,8 +143,6 @@ auto make_blob()
133143
str[1000] = '\r';
134144
str[1001] = '\n';
135145
return str;
136-
137-
return str;
138146
}
139147

140148
auto const blob = make_blob();
@@ -154,6 +162,8 @@ auto make_blob_string(std::string const& b)
154162
result<std::optional<int>> op_int_ok = 11;
155163
result<std::optional<bool>> op_bool_ok = true;
156164

165+
// clang-format off
166+
157167
// TODO: Test a streamed string that is not finished with a string of
158168
// size 0 but other command comes in.
159169
generic_response streamed_string_e1
@@ -461,12 +471,11 @@ generic_response const attr_e1b
461471
test(make_expected(S10b, node_type{{resp3::type::simple_error, 1UL, 0UL, {""}}}, {}, resp3::type::simple_error)); \
462472
test(make_expected(S12a, node_type{{resp3::type::blob_error, 1UL, 0UL, {"SYNTAX invalid syntax"}}}, {}, resp3::type::blob_error));\
463473
test(make_expected(S12b, node_type{{resp3::type::blob_error, 1UL, 0UL, {}}}, {}, resp3::type::blob_error));\
464-
test(make_expected(S12c, result<ignore_t>{}, boost::redis::error::resp3_blob_error));\
474+
test(make_expected(S12c, result<ignore_t>{}, boost::redis::error::resp3_blob_error));
465475

466-
BOOST_AUTO_TEST_CASE(sansio)
467-
{
468-
NUMBER_TEST_CONDITIONS(test_sync)
469-
}
476+
// clang-format on
477+
478+
BOOST_AUTO_TEST_CASE(sansio){NUMBER_TEST_CONDITIONS(test_sync)}
470479

471480
BOOST_AUTO_TEST_CASE(ignore_adapter_simple_error)
472481
{
@@ -478,10 +487,7 @@ BOOST_AUTO_TEST_CASE(ignore_adapter_blob_error)
478487
test_sync2(make_expected(S12a, ignore, boost::redis::error::resp3_blob_error));
479488
}
480489

481-
BOOST_AUTO_TEST_CASE(ignore_adapter_no_error)
482-
{
483-
test_sync2(make_expected(S05b, ignore));
484-
}
490+
BOOST_AUTO_TEST_CASE(ignore_adapter_no_error) { test_sync2(make_expected(S05b, ignore)); }
485491

486492
//-----------------------------------------------------------------------------------
487493
void check_error(char const* name, boost::redis::error ev)
@@ -492,10 +498,9 @@ void check_error(char const* name, boost::redis::error ev)
492498
BOOST_TEST(!ec.message().empty());
493499
BOOST_TEST(cat.equivalent(
494500
static_cast<std::underlying_type<boost::redis::error>::type>(ev),
495-
ec.category().default_error_condition(
496-
static_cast<std::underlying_type<boost::redis::error>::type>(ev))));
497-
BOOST_TEST(cat.equivalent(ec,
498-
static_cast<std::underlying_type<boost::redis::error>::type>(ev)));
501+
ec.category().default_error_condition(
502+
static_cast<std::underlying_type<boost::redis::error>::type>(ev))));
503+
BOOST_TEST(cat.equivalent(ec, static_cast<std::underlying_type<boost::redis::error>::type>(ev)));
499504
}
500505

501506
BOOST_AUTO_TEST_CASE(cover_error)
@@ -606,7 +611,7 @@ BOOST_AUTO_TEST_CASE(adapter_as)
606611
result<std::set<std::string>> set;
607612
auto adapter = adapt2(set);
608613

609-
for (auto const& e: set_expected1a.value()) {
614+
for (auto const& e : set_expected1a.value()) {
610615
error_code ec;
611616
adapter(e, ec);
612617
}

test/test_low_level_sync_sans_io.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(issue_210_non_empty_set_size_one)
144144
deserialize(wire, adapt2(resp));
145145

146146
BOOST_CHECK_EQUAL(std::get<0>(resp.value()).value(), 1);
147-
BOOST_CHECK_EQUAL(std::get<1>(resp.value()).value().size(), 1);
147+
BOOST_CHECK_EQUAL(std::get<1>(resp.value()).value().size(), 1u);
148148
BOOST_CHECK_EQUAL(std::get<1>(resp.value()).value().at(0), std::string{"foo"});
149149
BOOST_CHECK_EQUAL(std::get<2>(resp.value()).value(), "this_should_not_be_in_set");
150150
BOOST_CHECK_EQUAL(std::get<3>(resp.value()).value(), 2);
@@ -264,11 +264,11 @@ BOOST_AUTO_TEST_CASE(multiplexer_push)
264264
auto const ret = mpx.commit_read(ec);
265265

266266
BOOST_TEST(ret.first.value());
267-
BOOST_CHECK_EQUAL(ret.second, 16);
267+
BOOST_CHECK_EQUAL(ret.second, 16u);
268268

269269
// TODO: Provide operator << for generic_response so we can compare
270270
// the whole vector.
271-
BOOST_CHECK_EQUAL(resp.value().size(), 3);
271+
BOOST_CHECK_EQUAL(resp.value().size(), 3u);
272272
BOOST_CHECK_EQUAL(resp.value().at(1).value, "one");
273273
BOOST_CHECK_EQUAL(resp.value().at(2).value, "two");
274274

@@ -294,11 +294,11 @@ BOOST_AUTO_TEST_CASE(multiplexer_push_needs_more)
294294
ret = mpx.commit_read(ec);
295295

296296
BOOST_TEST(ret.first.value());
297-
BOOST_CHECK_EQUAL(ret.second, 16);
297+
BOOST_CHECK_EQUAL(ret.second, 16u);
298298

299299
// TODO: Provide operator << for generic_response so we can compare
300300
// the whole vector.
301-
BOOST_CHECK_EQUAL(resp.value().size(), 3);
301+
BOOST_CHECK_EQUAL(resp.value().size(), 3u);
302302
BOOST_CHECK_EQUAL(resp.value().at(1).value, "one");
303303
BOOST_CHECK_EQUAL(resp.value().at(2).value, "two");
304304
}
@@ -343,8 +343,8 @@ BOOST_AUTO_TEST_CASE(multiplexer_pipeline)
343343

344344
// There are three requests to coalesce, a second call should do
345345
// nothing.
346-
BOOST_CHECK_EQUAL(mpx.prepare_write(), 3);
347-
BOOST_CHECK_EQUAL(mpx.prepare_write(), 0);
346+
BOOST_CHECK_EQUAL(mpx.prepare_write(), 3u);
347+
BOOST_CHECK_EQUAL(mpx.prepare_write(), 0u);
348348

349349
// After coalescing the requests for writing their statuses should
350350
// be changed to "staged".
@@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(multiplexer_pipeline)
354354

355355
// There are no waiting requests to cancel since they are all
356356
// staged.
357-
BOOST_CHECK_EQUAL(mpx.cancel_waiting(), 0);
357+
BOOST_CHECK_EQUAL(mpx.cancel_waiting(), 0u);
358358

359359
// Since the requests haven't been sent (written) the done
360360
// callback should not have been called yet.
@@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(multiplexer_pipeline)
365365
// The commit_write call informs the multiplexer the payload was
366366
// sent (e.g. written to the socket). This step releases requests
367367
// that has no response.
368-
BOOST_CHECK_EQUAL(mpx.commit_write(), 1);
368+
BOOST_CHECK_EQUAL(mpx.commit_write(), 1u);
369369

370370
// The staged status should now have changed to written.
371371
BOOST_TEST(item1.elem_ptr->is_written());
@@ -387,7 +387,7 @@ BOOST_AUTO_TEST_CASE(multiplexer_pipeline)
387387

388388
// The read operation should have been successfull.
389389
BOOST_TEST(ret.first.has_value());
390-
BOOST_TEST(ret.second != 0);
390+
BOOST_TEST(ret.second != 0u);
391391

392392
// The read buffer should also be empty now
393393
BOOST_TEST(mpx.get_read_buffer().empty());

0 commit comments

Comments
 (0)