From bfdef8b15df0d5d9d036196bc5f4a6d4203c3440 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 13 Sep 2025 08:35:35 -0700 Subject: [PATCH] Remove deprecated functions --- ChangeLog.md | 10 ++++++-- doc/api.md | 4 ++-- include/fmt/chrono.h | 12 ---------- include/fmt/format-inl.h | 5 ---- include/fmt/printf.h | 46 ++++++++++++++---------------------- include/fmt/xchar.h | 12 ---------- test/printf-test.cc | 51 +++++----------------------------------- 7 files changed, 34 insertions(+), 106 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 38414ce0..5630368d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -74,10 +74,16 @@ formatters (https://github.com/fmtlib/fmt/issues/4424, https://github.com/fmtlib/fmt/pull/4434). Thanks @jeremy-rifkin. -- Removed deprecated `basic_format_args::parse_context_type` and +- Removed the deprecated `has_formatter` trait. Use `is_formattable` instead. + +- Removed the deprecated `basic_format_args::parse_context_type`, `basic_format_args::formatter_type` and similar aliases in context types. -- Removed deprecated `has_formatter`. Use `is_formattable` instead. +- Removed the deprecated wide stream overload of `fmt::printf` and deprecated + wide overloads of `fmt::fprintf` and `fmt::sprintf`. + +- Removed the deprecated wide stream overloads of `fmt::print` that take text + styles. - Removed legacy `is_*char` traits. diff --git a/doc/api.md b/doc/api.md index 2bc5b0d1..2c584abc 100644 --- a/doc/api.md +++ b/doc/api.md @@ -674,9 +674,9 @@ if an argument type doesn't match its format specification. ::: printf(string_view, const T&...) -::: fprintf(std::FILE*, const S&, const T&...) +::: fprintf(std::FILE*, string_view, const T&...) -::: sprintf(const S&, const T&...) +::: sprintf(string_view, const T&...) ## Wide Strings diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index f9e3dd2b..c511a04a 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -513,19 +513,7 @@ struct time_zone { template auto current_zone(T...) -> time_zone* { return nullptr; } - -template void _tzset(T...) {} } // namespace tz - -// DEPRECATED! -inline void tzset_once() { - static bool init = []() { - using namespace tz; - _tzset(); - return false; - }(); - ignore_unused(init); -} } // namespace detail FMT_BEGIN_EXPORT diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index acf7e8b9..9d568dca 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -75,11 +75,6 @@ template auto locale_ref::get() const -> Locale { namespace detail { -// DEPRECATED! -FMT_FUNC void assert_fail(const char* file, int line, const char* message) { - fmt::assert_fail(file, line, message); -} - FMT_FUNC void format_error_code(detail::buffer& out, int error_code, string_view message) noexcept { // Report error code making sure that the output fits into diff --git a/include/fmt/printf.h b/include/fmt/printf.h index cd6a99b2..ab3f2774 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -18,10 +18,6 @@ FMT_BEGIN_NAMESPACE FMT_BEGIN_EXPORT -template struct printf_formatter { - printf_formatter() = delete; -}; - template class basic_printf_context { private: basic_appender out_; @@ -33,8 +29,6 @@ template class basic_printf_context { public: using char_type = Char; - using parse_context_type = parse_context; - template using formatter_type = printf_formatter; enum { builtin_types = 1 }; /// Constructs a `printf_context` object. References to the arguments are @@ -74,7 +68,7 @@ inline auto find(const char* first, const char* last, char value, // Checks if a value fits in int - used to avoid warnings about comparing // signed and unsigned integers. -template struct int_checker { +template struct int_checker { template static auto fits_in_int(T value) -> bool { return value <= to_unsigned(max_value()); } @@ -570,15 +564,19 @@ inline auto vsprintf(basic_string_view fmt, * * std::string message = fmt::sprintf("The answer is %d", 42); */ -template > -inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string { - return vsprintf(detail::to_string_view(fmt), - fmt::make_format_args>(args...)); +template +inline auto sprintf(string_view fmt, const T&... args) -> std::string { + return vsprintf(fmt, make_printf_args(args...)); +} +template +FMT_DEPRECATED auto sprintf(basic_string_view fmt, const T&... args) + -> std::wstring { + return vsprintf(fmt, make_printf_args(args...)); } template -inline auto vfprintf(std::FILE* f, basic_string_view fmt, - typename vprintf_args::type args) -> int { +auto vfprintf(std::FILE* f, basic_string_view fmt, + typename vprintf_args::type args) -> int { auto buf = basic_memory_buffer(); detail::vprintf(buf, fmt, args); size_t size = buf.size(); @@ -595,17 +593,14 @@ inline auto vfprintf(std::FILE* f, basic_string_view fmt, * * fmt::fprintf(stderr, "Don't %s!", "panic"); */ -template > -inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int { - return vfprintf(f, detail::to_string_view(fmt), - make_printf_args(args...)); +template +inline auto fprintf(std::FILE* f, string_view fmt, const T&... args) -> int { + return vfprintf(f, fmt, make_printf_args(args...)); } - -template -FMT_DEPRECATED inline auto vprintf(basic_string_view fmt, - typename vprintf_args::type args) - -> int { - return vfprintf(stdout, fmt, args); +template +FMT_DEPRECATED auto fprintf(std::FILE* f, basic_string_view fmt, + const T&... args) -> int { + return vfprintf(f, fmt, make_printf_args(args...)); } /** @@ -620,11 +615,6 @@ template inline auto printf(string_view fmt, const T&... args) -> int { return vfprintf(stdout, fmt, make_printf_args(args...)); } -template -FMT_DEPRECATED inline auto printf(basic_string_view fmt, - const T&... args) -> int { - return vfprintf(stdout, fmt, make_printf_args(args...)); -} FMT_END_EXPORT FMT_END_NAMESPACE diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 51c5cfc1..9334b87f 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -330,18 +330,6 @@ inline auto format(text_style ts, wformat_string fmt, T&&... args) return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...)); } -template -FMT_DEPRECATED void print(std::FILE* f, text_style ts, wformat_string fmt, - const T&... args) { - vprint(f, ts, fmt, fmt::make_wformat_args(args...)); -} - -template -FMT_DEPRECATED void print(text_style ts, wformat_string fmt, - const T&... args) { - return print(stdout, ts, fmt, args...); -} - inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) { auto buffer = basic_memory_buffer(); detail::vformat_to(buffer, fmt, args); diff --git a/test/printf-test.cc b/test/printf-test.cc index ee5cf0b0..277a3b67 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -6,16 +6,12 @@ // For the license information refer to format.h. #include "fmt/printf.h" -// include if possible for https://github.com/fmtlib/fmt/pull/4042 -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L -# include -#endif #include #include #include -#include "fmt/xchar.h" +#include "fmt/xchar.h" // DEPRECATED! #include "gtest-extra.h" #include "util.h" @@ -26,27 +22,21 @@ using fmt::detail::max_value; const unsigned big_num = INT_MAX + 1u; // Makes format string argument positional. -static std::string make_positional(fmt::string_view format) { +static auto make_positional(fmt::string_view format) -> std::string { std::string s(format.data(), format.size()); s.replace(s.find('%'), 1, "%1$"); return s; } -static std::wstring make_positional(fmt::basic_string_view format) { - std::wstring s(format.data(), format.size()); - s.replace(s.find(L'%'), 1, L"%1$"); - return s; -} - // A wrapper around fmt::sprintf to workaround bogus warnings about invalid // format strings in MSVC. template -std::string test_sprintf(fmt::string_view format, const Args&... args) { +auto test_sprintf(fmt::string_view format, const Args&... args) -> std::string { return fmt::sprintf(format, args...); } template -std::wstring test_sprintf(fmt::basic_string_view format, - const Args&... args) { +auto test_sprintf(fmt::basic_string_view format, const Args&... args) + -> std::wstring { return fmt::sprintf(format, args...); } @@ -55,10 +45,7 @@ std::wstring test_sprintf(fmt::basic_string_view format, << "format: " << format; \ EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg)) -TEST(printf_test, no_args) { - EXPECT_EQ("test", test_sprintf("test")); - EXPECT_EQ(L"test", fmt::sprintf(L"test")); -} +TEST(printf_test, no_args) { EXPECT_EQ("test", test_sprintf("test")); } TEST(printf_test, escape) { EXPECT_EQ("%", test_sprintf("%%")); @@ -66,11 +53,6 @@ TEST(printf_test, escape) { EXPECT_EQ("% after", test_sprintf("%% after")); EXPECT_EQ("before % after", test_sprintf("before %% after")); EXPECT_EQ("%s", test_sprintf("%%s")); - EXPECT_EQ(L"%", fmt::sprintf(L"%%")); - EXPECT_EQ(L"before %", fmt::sprintf(L"before %%")); - EXPECT_EQ(L"% after", fmt::sprintf(L"%% after")); - EXPECT_EQ(L"before % after", fmt::sprintf(L"before %% after")); - EXPECT_EQ(L"%s", fmt::sprintf(L"%%s")); } TEST(printf_test, positional_args) { @@ -467,9 +449,6 @@ TEST(printf_test, char) { EXPECT_PRINTF("x", "%c", 'x'); int max = max_value(); EXPECT_PRINTF(fmt::format("{}", static_cast(max)), "%c", max); - // EXPECT_PRINTF("x", "%lc", L'x'); - EXPECT_PRINTF(L"x", L"%c", L'x'); - EXPECT_PRINTF(fmt::format(L"{}", static_cast(max)), L"%c", max); } TEST(printf_test, string) { @@ -477,10 +456,6 @@ TEST(printf_test, string) { const char* null_str = nullptr; EXPECT_PRINTF("(null)", "%s", null_str); EXPECT_PRINTF(" (null)", "%10s", null_str); - EXPECT_PRINTF(L"abc", L"%s", L"abc"); - const wchar_t* null_wstr = nullptr; - EXPECT_PRINTF(L"(null)", L"%s", null_wstr); - EXPECT_PRINTF(L" (null)", L"%10s", null_wstr); } TEST(printf_test, pointer) { @@ -494,16 +469,6 @@ TEST(printf_test, pointer) { EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s); const char* null_str = nullptr; EXPECT_PRINTF("(nil)", "%p", null_str); - - p = &n; - EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p); - p = nullptr; - EXPECT_PRINTF(L"(nil)", L"%p", p); - EXPECT_PRINTF(L" (nil)", L"%10p", p); - const wchar_t* w = L"test"; - EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w); - const wchar_t* null_wstr = nullptr; - EXPECT_PRINTF(L"(nil)", L"%p", null_wstr); } enum test_enum { answer = 42 }; @@ -531,10 +496,6 @@ TEST(printf_test, printf_error) { } #endif -TEST(printf_test, wide_string) { - EXPECT_EQ(L"abc", fmt::sprintf(L"%s", L"abc")); -} - TEST(printf_test, vprintf) { int n = 42; auto store = fmt::make_format_args(n);