Skip to content

Commit

Permalink
Remove legacy workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 9, 2024
1 parent c177324 commit e185eda
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
39 changes: 11 additions & 28 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1901,12 +1901,7 @@ using is_formattable = bool_constant<!std::is_base_of<
\endrst
*/
template <typename Context, size_t NUM_NAMED_ARGS, typename... Args>
class format_arg_store_impl
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
// Workaround a GCC template argument substitution bug.
: public basic_format_args<Context>
#endif
{
class format_arg_store_impl {
private:
static const size_t num_args = sizeof...(Args);
static const bool is_packed = num_args <= detail::max_packed_args;
Expand All @@ -1923,11 +1918,7 @@ class format_arg_store_impl
public:
template <typename... T>
FMT_CONSTEXPR FMT_INLINE format_arg_store_impl(T&... args)
:
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
basic_format_args<Context>(*this),
#endif
args_{value_type(named_args_, NUM_NAMED_ARGS),
: args_{value_type(named_args_, NUM_NAMED_ARGS),
detail::make_arg<is_packed, Context>(args)...} {
detail::init_named_args(named_args_, 0, 0, args...);
}
Expand All @@ -1944,13 +1935,9 @@ class format_arg_store_impl
}
};

// A specialization of format_arg_store_impl without named arguments.
template <typename Context, typename... Args>
class format_arg_store_impl<Context, 0, Args...>
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
// Workaround a GCC template argument substitution bug.
: public basic_format_args<Context>
#endif
{
class format_arg_store_impl<Context, 0, Args...> {
private:
static const size_t num_args = sizeof...(Args);
static const bool is_packed = num_args <= detail::max_packed_args;
Expand All @@ -1964,12 +1951,7 @@ class format_arg_store_impl<Context, 0, Args...>
public:
template <typename... T>
FMT_CONSTEXPR FMT_INLINE format_arg_store_impl(T&... args)
:
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
basic_format_args<Context>(*this),
#endif
args_{detail::make_arg<is_packed, Context>(args)...} {
}
: args_{detail::make_arg<is_packed, Context>(args)...} {}

static constexpr unsigned long long desc =
(is_packed ? detail::encode_types<Context, Args...>()
Expand All @@ -1986,10 +1968,10 @@ using format_arg_store =

/**
\rst
Constructs a `~fmt::format_arg_store` object that contains references to
arguments and can be implicitly converted to `~fmt::format_args`. `Context`
can be omitted in which case it defaults to `~fmt::format_context`.
See `~fmt::arg` for lifetime considerations.
Constructs an object that stores references to arguments and can be implicitly
converted to `~fmt::format_args`. `Context` can be omitted in which case it
defaults to `~fmt::format_context`. See `~fmt::arg` for lifetime
considerations.
\endrst
*/
// Take arguments by lvalue references to avoid some lifetime issues, e.g.
Expand Down Expand Up @@ -2739,7 +2721,8 @@ template <> struct vformat_args<char> {
using type = format_args;
};

// Use vformat_args and avoid type_identity to keep symbols short.
// Use vformat_args and avoid type_identity, keep symbols short and workaround
// a GCC <= 4.8 bug.
template <typename Char>
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
typename vformat_args<Char>::type args, locale_ref loc = {});
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ inline void vprint_directly(std::ostream& os, string_view format_str,
FMT_EXPORT template <typename Char>
void vprint(std::basic_ostream<Char>& os,
basic_string_view<type_identity_t<Char>> format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
typename detail::vformat_args<Char>::type args) {
auto buffer = basic_memory_buffer<Char>();
detail::vformat_to(buffer, format_str, args);
if (detail::write_ostream_unicode(os, {buffer.data(), buffer.size()})) return;
Expand Down
9 changes: 6 additions & 3 deletions include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,13 @@ inline auto make_wprintf_args(const T&... args)
return {args...};
}

template <typename Char> struct vprintf_args {
using type = basic_format_args<basic_printf_context<Char>>;
};

template <typename Char>
inline auto vsprintf(
basic_string_view<Char> fmt,
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
inline auto vsprintf(basic_string_view<Char> fmt,
typename vprintf_args<Char>::type args)
-> std::basic_string<Char> {
auto buf = basic_memory_buffer<Char>();
detail::vprintf(buf, fmt, args);
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ auto join(const std::tuple<T...>& tuple, basic_string_view<wchar_t> sep)

template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
auto vformat(basic_string_view<Char> format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args)
typename detail::vformat_args<Char>::type args)
-> std::basic_string<Char> {
auto buf = basic_memory_buffer<Char>();
detail::vformat_to(buf, format_str, args);
Expand Down

0 comments on commit e185eda

Please sign in to comment.