diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 0f7a90051f37c..affd793e343ac 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -643,7 +643,7 @@ FMT_INLINE std::basic_string format(const S&, #ifdef __cpp_if_constexpr if constexpr (std::is_same::value) { constexpr basic_string_view str = S(); - if (str.size() == 2 && str[0] == '{' && str[1] == '}') + if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') return fmt::to_string(detail::first(args...)); } #endif diff --git a/include/fmt/format.h b/include/fmt/format.h index afcb32f5cf3eb..8ec527e6a0a77 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3538,7 +3538,7 @@ struct formatter : formatter { \ template \ auto format(Type const& val, FormatContext& ctx) -> decltype(ctx.out()) { \ - return formatter::format(val, ctx); \ + return formatter::format(static_cast(val), ctx); \ } \ } @@ -3552,6 +3552,9 @@ FMT_FORMAT_AS(Char*, const Char*); FMT_FORMAT_AS(std::basic_string, basic_string_view); FMT_FORMAT_AS(std::nullptr_t, const void*); FMT_FORMAT_AS(detail::std_string_view, basic_string_view); +#if __cplusplus >= 201703L +FMT_FORMAT_AS(std::byte, unsigned); +#endif template struct formatter : formatter { diff --git a/test/compile-test.cc b/test/compile-test.cc index 660f4fb1a0eaf..7ae28772038ad 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -173,6 +173,10 @@ TEST(CompileTest, TextAndArg) { EXPECT_EQ(">>>42<<<", fmt::format(FMT_COMPILE(">>>{}<<<"), 42)); EXPECT_EQ("42!", fmt::format(FMT_COMPILE("{}!"), 42)); } + +TEST(CompileTest, Empty) { + EXPECT_EQ("", fmt::format(FMT_COMPILE(""))); +} #endif #if __cplusplus >= 202002L diff --git a/test/format-test.cc b/test/format-test.cc index 205997ec827f2..bb10460f40f47 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1762,6 +1762,13 @@ TEST(FormatTest, JoinArg) { #endif } +#if __cplusplus >= 201703L +TEST(FormatTest, JoinBytes) { + std::vector v = {std::byte(1), std::byte(2), std::byte(3)}; + EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, ", "))); +} +#endif + template std::string str(const T& value) { return fmt::format("{}", value); }