Skip to content

Commit

Permalink
rpc: Fix formatting on some fmt lib versions
Browse files Browse the repository at this point in the history
There's a bug in fmt-8 that prefers implicit type cast to bool over
overloaded operator<< when formatting it with the latter. As a result
the formatted string is always "true"/"false" instead of some sane
value.

Marking the operator bool() explicit solves the issue. Also add a test
to catch any violations earlier.

fixes: #1151

Signed-off-by: Pavel Emelyanov <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
xemul authored and avikivity committed Jul 25, 2022
1 parent c3169e0 commit f1d0b25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/seastar/rpc/rpc_types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct connection_id {
bool operator==(const connection_id& o) const {
return id == o.id;
}
operator bool() const {
explicit operator bool() const {
return shard() != 0xffff;
}
size_t shard() const {
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/rpc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1401,4 +1401,11 @@ SEASTAR_TEST_CASE(test_loggers) {
});
}

SEASTAR_TEST_CASE(test_connection_id_format) {
rpc::connection_id cid = rpc::connection_id::make_id(0x123, 1);
std::string res = format("{}", cid);
BOOST_REQUIRE_EQUAL(res, "1230001");
return make_ready_future<>();
}

static_assert(std::is_same_v<decltype(rpc::tuple(1U, 1L)), rpc::tuple<unsigned, long>>, "rpc::tuple deduction guid not working");

0 comments on commit f1d0b25

Please sign in to comment.