From 45ed657df3c80a20fb78cb3587320ee04fe63903 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 1 Feb 2026 08:22:38 -0800 Subject: [PATCH] Cleanup locking --- include/fmt/base.h | 30 ++++++++++++------------------ test/format-test.cc | 2 ++ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index c25db9ce..bb883cbf 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -623,6 +623,9 @@ struct formatter { formatter() = delete; }; +template +struct locking : std::false_type {}; + /// Reports a format error at compile time or, via a `format_error` exception, /// at runtime. // This function is intentionally not constexpr to give a compile-time error. @@ -2292,8 +2295,6 @@ template struct native_formatter { dynamic_format_specs specs_; public: - using nonlocking = void; - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); @@ -2313,19 +2314,12 @@ template struct native_formatter { -> decltype(ctx.out()); }; -template -struct locking - : bool_constant::value == type::custom_type> {}; -template -struct locking>::nonlocking>> - : std::false_type {}; - -template constexpr inline auto is_locking() -> bool { - return locking::value; +template constexpr auto is_locking() -> bool { + return locking>::value; } template -constexpr inline auto is_locking() -> bool { - return locking::value || is_locking(); +constexpr auto is_locking() -> bool { + return locking>::value || is_locking(); } FMT_API void vformat_to(buffer& buf, string_view fmt, format_args args, @@ -2835,8 +2829,8 @@ FMT_INLINE void print(format_string fmt, T&&... args) { vargs va = {{args...}}; if FMT_CONSTEXPR20 (!detail::use_utf8) return detail::vprint_mojibake(stdout, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(stdout, fmt.str, va) - : vprint(fmt.str, va); + detail::is_locking() ? vprint_buffered(stdout, fmt.str, va) + : vprint(fmt.str, va); } /** @@ -2852,8 +2846,8 @@ FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { vargs va = {{args...}}; if FMT_CONSTEXPR20 (!detail::use_utf8) return detail::vprint_mojibake(f, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(f, fmt.str, va) - : vprint(f, fmt.str, va); + detail::is_locking() ? vprint_buffered(f, fmt.str, va) + : vprint(f, fmt.str, va); } /// Formats `args` according to specifications in `fmt` and writes the output @@ -2869,7 +2863,7 @@ FMT_INLINE void println(FILE* f, format_string fmt, T&&... args) { /// to `stdout` followed by a newline. template FMT_INLINE void println(format_string fmt, T&&... args) { - return fmt::println(stdout, fmt, static_cast(args)...); + fmt::println(stdout, fmt, static_cast(args)...); } FMT_PRAGMA_CLANG(diagnostic pop) diff --git a/test/format-test.cc b/test/format-test.cc index 9efde149..94c69f78 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1953,6 +1953,8 @@ template <> struct formatter { return format_to(ctx.out(), "{}", d.value); } }; + +template <> struct locking : std::true_type {}; FMT_END_NAMESPACE TEST(format_test, locking_formatter) {