diff --git a/include/fmt/args.h b/include/fmt/args.h index 1eb9c538..6ed30c0b 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -110,14 +110,14 @@ template class dynamic_format_arg_store { } template void emplace_arg(const T& arg) { - data_.emplace_back(detail::make_arg(arg)); + data_.emplace_back(arg); } template void emplace_arg(const detail::named_arg& arg) { if (named_info_.empty()) data_.insert(data_.begin(), basic_format_arg(nullptr, 0)); - data_.emplace_back(detail::make_arg(detail::unwrap(arg.value))); + data_.emplace_back(detail::unwrap(arg.value)); auto pop_one = [](std::vector>* data) { data->pop_back(); }; diff --git a/include/fmt/format.h b/include/fmt/format.h index c2ee7102..bd4ae809 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -995,12 +995,6 @@ struct is_contiguous> : std::true_type { FMT_END_EXPORT namespace detail { - -template -FMT_CONSTEXPR auto make_arg(T& val) -> basic_format_arg { - return {arg_mapper::map(val)}; -} - FMT_API auto write_console(int fd, string_view text) -> bool; FMT_API void print(FILE*, string_view); } // namespace detail @@ -1092,7 +1086,7 @@ class loc_value { public: template ::value)> - loc_value(T value) : value_(detail::make_arg(value)) {} + loc_value(T value) : value_(value) {} template ::value)> loc_value(T) {} diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 309d6076..7a1c5081 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -145,25 +145,19 @@ template class arg_converter { using target_type = conditional_t::value, U, T>; if (const_check(sizeof(target_type) <= sizeof(int))) { // Extra casts are used to silence warnings. - if (is_signed) { - auto n = static_cast(static_cast(value)); - arg_ = detail::make_arg(n); - } else { - using unsigned_type = typename make_unsigned_or_bool::type; - auto n = static_cast(static_cast(value)); - arg_ = detail::make_arg(n); - } + using unsigned_type = typename make_unsigned_or_bool::type; + if (is_signed) + arg_ = static_cast(static_cast(value)); + else + arg_ = static_cast(static_cast(value)); } else { - if (is_signed) { - // glibc's printf doesn't sign extend arguments of smaller types: - // std::printf("%lld", -42); // prints "4294967254" - // but we don't have to do the same because it's a UB. - auto n = static_cast(value); - arg_ = detail::make_arg(n); - } else { - auto n = static_cast::type>(value); - arg_ = detail::make_arg(n); - } + // glibc's printf doesn't sign extend arguments of smaller types: + // std::printf("%lld", -42); // prints "4294967254" + // but we don't have to do the same because it's a UB. + if (is_signed) + arg_ = static_cast(value); + else + arg_ = static_cast::type>(value); } } @@ -190,8 +184,7 @@ template class char_converter { template ::value)> void operator()(T value) { - auto c = static_cast(value); - arg_ = detail::make_arg(c); + arg_ = static_cast(value); } template ::value)> @@ -471,7 +464,7 @@ void vprintf(buffer& buf, basic_string_view format, auto nul = std::find(str, str_end, Char()); auto sv = basic_string_view( str, to_unsigned(nul != str_end ? nul - str : specs.precision)); - arg = make_arg>(sv); + arg = sv; } if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt(); if (specs.fill_unit() == '0') { diff --git a/test/base-test.cc b/test/base-test.cc index b8a69b17..3189858a 100644 --- a/test/base-test.cc +++ b/test/base-test.cc @@ -342,14 +342,12 @@ VISIT_TYPE(unsigned long, unsigned long long); #endif #if FMT_BUILTIN_TYPES -# define CHECK_ARG(expected, value) \ - { \ - testing::StrictMock> visitor; \ - EXPECT_CALL(visitor, visit(expected)); \ - auto var = value; \ - fmt::basic_format_arg( \ - fmt::detail::arg_mapper::map(var)) \ - .visit(visitor); \ +# define CHECK_ARG(expected, value) \ + { \ + testing::StrictMock> visitor; \ + EXPECT_CALL(visitor, visit(expected)); \ + auto var = value; \ + fmt::basic_format_arg(var).visit(visitor); \ } #else # define CHECK_ARG(expected, value)