From 8103144ff87f99dd33462fc09d69f07ef966fdbf Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Thu, 10 Feb 2022 00:59:11 +0500 Subject: [PATCH 1/2] Replace make_args_checked to make_format_args --- include/fmt/color.h | 6 +++--- include/fmt/format.h | 2 +- include/fmt/ostream.h | 2 +- include/fmt/xchar.h | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index e46843c3f621..6d794c59e557 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -547,7 +547,7 @@ template (format_str, args...)); + fmt::make_format_args>>(args...)); } /** @@ -592,7 +592,7 @@ template > inline std::basic_string format(const text_style& ts, const S& format_str, const Args&... args) { return fmt::vformat(ts, to_string_view(format_str), - fmt::make_args_checked(format_str, args...)); + fmt::make_format_args>(args...)); } /** @@ -627,7 +627,7 @@ inline auto format_to(OutputIt out, const text_style& ts, const S& format_str, Args&&... args) -> typename std::enable_if::type { return vformat_to(out, ts, to_string_view(format_str), - fmt::make_args_checked(format_str, args...)); + fmt::make_format_args>>(args...)); } FMT_MODULE_EXPORT_END diff --git a/include/fmt/format.h b/include/fmt/format.h index afcba52ed043..79f2c943fad0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2561,7 +2561,7 @@ template struct udl_formatter { template auto operator()(T&&... args) const -> std::basic_string { - return vformat(str, fmt::make_args_checked(str, args...)); + return vformat(str, fmt::make_format_args>(args...)); } }; diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 2bb79bbb768a..567303d389f4 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -136,7 +136,7 @@ template ::value, char_t>> void print(std::basic_ostream& os, const S& format_str, Args&&... args) { vprint(os, to_string_view(format_str), - fmt::make_args_checked(format_str, args...)); + fmt::make_format_args>(args...)); } FMT_END_NAMESPACE diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 55825077f8ed..9b57815d08bc 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -92,8 +92,8 @@ auto vformat(basic_string_view format_str, template , FMT_ENABLE_IF(!std::is_same::value)> auto format(const S& format_str, Args&&... args) -> std::basic_string { - const auto& vargs = fmt::make_args_checked(format_str, args...); - return vformat(to_string_view(format_str), vargs); + return vformat(to_string_view(format_str), + fmt::make_format_args>(args...)); } template , @@ -113,7 +113,7 @@ template std::basic_string { return detail::vformat(loc, to_string_view(format_str), - fmt::make_args_checked(format_str, args...)); + fmt::make_format_args>(args...)); } template , @@ -132,8 +132,8 @@ template ::value&& detail::is_exotic_char::value)> inline auto format_to(OutputIt out, const S& fmt, Args&&... args) -> OutputIt { - const auto& vargs = fmt::make_args_checked(fmt, args...); - return vformat_to(out, to_string_view(fmt), vargs); + return vformat_to(out, to_string_view(fmt), + fmt::make_format_args>(args...)); } template & buf, const S& format_str, Args&&... args) -> typename buffer_context::iterator { - const auto& vargs = fmt::make_args_checked(format_str, args...); - detail::vformat_to(buf, to_string_view(format_str), vargs, {}); + detail::vformat_to(buf, to_string_view(format_str), + fmt::make_format_args>(args...), {}); return detail::buffer_appender(buf); } @@ -167,8 +167,8 @@ template < inline auto format_to(OutputIt out, const Locale& loc, const S& format_str, Args&&... args) -> typename std::enable_if::type { - const auto& vargs = fmt::make_args_checked(format_str, args...); - return vformat_to(out, loc, to_string_view(format_str), vargs); + return vformat_to(out, loc, to_string_view(format_str), + fmt::make_format_args>(args...)); } template ::value)> inline auto format_to_n(OutputIt out, size_t n, const S& fmt, const Args&... args) -> format_to_n_result { - const auto& vargs = fmt::make_args_checked(fmt, args...); - return vformat_to_n(out, n, to_string_view(fmt), vargs); + return vformat_to_n(out, n, to_string_view(fmt), + fmt::make_format_args>(args...)); } template , FMT_ENABLE_IF(detail::is_exotic_char::value)> inline auto formatted_size(const S& fmt, Args&&... args) -> size_t { detail::counting_buffer buf; - const auto& vargs = fmt::make_args_checked(fmt, args...); - detail::vformat_to(buf, to_string_view(fmt), vargs); + detail::vformat_to(buf, to_string_view(fmt), + fmt::make_format_args>(args...)); return buf.count(); } From bdfec1dc88cbcdeb7381f373f15907e0a8fc13fd Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Thu, 10 Feb 2022 01:06:10 +0500 Subject: [PATCH 2/2] Deprecate legacy make_args_checked --- doc/api.rst | 5 +---- include/fmt/format.h | 4 ++-- test/module-test.cc | 7 ------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 46070ed6b844..5f7cba51c562 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -113,8 +113,7 @@ binary footprint, for example (https://godbolt.org/z/oba4Mc): template void log(const char* file, int line, const S& format, Args&&... args) { - vlog(file, line, format, - fmt::make_args_checked(format, args...)); + vlog(file, line, format, fmt::make_format_args(args...)); } #define MY_LOG(format, ...) \ @@ -125,8 +124,6 @@ binary footprint, for example (https://godbolt.org/z/oba4Mc): Note that ``vlog`` is not parameterized on argument types which improves compile times and reduces binary code size compared to a fully parameterized version. -.. doxygenfunction:: fmt::make_args_checked(const S&, const remove_reference_t&...) - .. doxygenfunction:: fmt::make_format_args(const Args&...) .. doxygenclass:: fmt::format_arg_store diff --git a/include/fmt/format.h b/include/fmt/format.h index 79f2c943fad0..99d1af6d9d21 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -834,8 +834,8 @@ class FMT_API format_error : public std::runtime_error { \endrst */ template > -FMT_INLINE auto make_args_checked(const S& fmt, - const remove_reference_t&... args) +FMT_DEPRECATED FMT_INLINE auto make_args_checked( + const S& fmt, const remove_reference_t&... args) -> format_arg_store, remove_reference_t...> { static_assert( detail::count<( diff --git a/test/module-test.cc b/test/module-test.cc index 7fbf763d7b6e..62e5fe8baea8 100644 --- a/test/module-test.cc +++ b/test/module-test.cc @@ -195,13 +195,6 @@ TEST(module_test, wformat_args) { EXPECT_TRUE(args.get(0)); } -TEST(module_test, checked_format_args) { - fmt::basic_format_args args = fmt::make_args_checked("{}", 42); - EXPECT_TRUE(args.get(0)); - fmt::basic_format_args wargs = fmt::make_args_checked(L"{}", 42); - EXPECT_TRUE(wargs.get(0)); -} - TEST(module_test, dynamic_format_args) { fmt::dynamic_format_arg_store dyn_store; dyn_store.push_back(fmt::arg("a42", 42));