From 1521bba701a59ecf7907c2bee1af09f8aead362a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 2 Nov 2024 07:49:55 -0700 Subject: [PATCH] Use consistent types for argument count --- include/fmt/base.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index a8938e49..35a483dd 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1023,15 +1023,15 @@ template struct named_arg : view { static_assert(!is_named_arg::value, "nested named arguments"); }; -template constexpr auto count() -> size_t { return B ? 1 : 0; } -template constexpr auto count() -> size_t { +template constexpr auto count() -> int { return B ? 1 : 0; } +template constexpr auto count() -> int { return (B1 ? 1 : 0) + count(); } -template constexpr auto count_named_args() -> size_t { +template constexpr auto count_named_args() -> int { return count::value...>(); } -template constexpr auto count_static_named_args() -> size_t { +template constexpr auto count_static_named_args() -> int { return count::value...>(); } @@ -2280,11 +2280,11 @@ constexpr auto make_descriptor() -> unsigned long long { : is_unpacked_bit | NUM_ARGS; } -template +template using arg_t = conditional_t, basic_format_arg>; -template struct named_arg_store { // args_[0].named_args points to named_args to avoid bloating format_args. @@ -2316,13 +2316,13 @@ struct named_arg_store { // An array of references to arguments. It can be implicitly converted to // `basic_format_args` for passing into type-erased formatting functions // such as `vformat`. It is a plain struct to reduce binary size in debug mode. -template struct format_arg_store { // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. using type = conditional_t[max_of(1, NUM_ARGS)], + arg_t[max_of(1, NUM_ARGS)], named_arg_store>; type args; }; @@ -2534,7 +2534,7 @@ template class basic_format_args { return static_cast((desc_ >> shift) & mask); } - template + template using store = detail::format_arg_store; @@ -2544,14 +2544,14 @@ template class basic_format_args { constexpr basic_format_args() : desc_(0), args_(nullptr) {} /// Constructs a `basic_format_args` object from `format_arg_store`. - template constexpr FMT_ALWAYS_INLINE basic_format_args( const store& s) : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), values_(s.args) {} - template detail::max_packed_args)> constexpr basic_format_args(const store& s) : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), @@ -2658,14 +2658,12 @@ inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; } /// A compile-time format string. template struct fstring { private: - static constexpr size_t num_static_named_args = + static constexpr int num_static_named_args = detail::count_static_named_args(); - using checker = - detail::format_string_checker(sizeof...(T)), - static_cast(num_static_named_args), - num_static_named_args != - detail::count_named_args()>; + using checker = detail::format_string_checker< + char, static_cast(sizeof...(T)), num_static_named_args, + num_static_named_args != detail::count_named_args()>; using arg_pack = detail::arg_pack; @@ -2745,8 +2743,8 @@ struct formatter(), + int NUM_ARGS = sizeof...(T), + int NUM_NAMED_ARGS = detail::count_named_args(), unsigned long long DESC = detail::make_descriptor()> constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args) -> detail::format_arg_store {