Skip to content

Commit

Permalink
sstring: inherit publicly from sstring_view formatter
Browse files Browse the repository at this point in the history
fmt 10 detects if a formatter provides some method (set_debug_format()),
but the detection fails if the method is private and compilation breaks
on clang [1].

Work around the clang bug by inheriting publicly.

[1] llvm/llvm-project#68849

A test case reproducing the problem is included (thanks
Kefu Chai <kefu.chai@scylladb.com>).
  • Loading branch information
avikivity committed Oct 17, 2023
1 parent bab1625 commit e4cd64b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/seastar/core/sstring.hh
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,13 @@ std::ostream& operator<<(std::ostream& os, const std::unordered_map<Key, T, Hash

#if FMT_VERSION >= 90000

// Due to https://github.com/llvm/llvm-project/issues/68849, we inherit
// from formatter<string_view> publicly rather than privately

SEASTAR_MODULE_EXPORT
template <typename char_type, typename Size, Size max_size, bool NulTerminate>
struct fmt::formatter<seastar::basic_sstring<char_type, Size, max_size, NulTerminate>>
: private fmt::formatter<std::basic_string_view<char_type>> {
: public fmt::formatter<std::basic_string_view<char_type>> {
using format_as_t = std::basic_string_view<char_type>;
using base = fmt::formatter<format_as_t>;
using base::parse;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/sstring_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <boost/test/unit_test.hpp>
#include <seastar/core/sstring.hh>
#include <list>
#include <fmt/ranges.h>
#include <fmt/std.h>

using namespace std::literals;
using namespace seastar;
Expand Down Expand Up @@ -306,3 +308,16 @@ BOOST_AUTO_TEST_CASE(test_compares_left_hand_not_string) {
BOOST_REQUIRE(std::string("a") < sstring("b"));
#endif
}

#if FMT_VERSION >= 90000

BOOST_AUTO_TEST_CASE(test_fmt) {
#if FMT_VERSION >= 100000 // formatting of std::optional was introduced in fmt 10
// https://github.com/llvm/llvm-project/issues/68849
std::ignore = fmt::format("{}", std::optional(sstring{"hello"}));
#endif
std::vector<sstring> strings;
std::ignore = fmt::format("{}", strings);
}

#endif

0 comments on commit e4cd64b

Please sign in to comment.