From 2d2326a76d78b170616c2cc854eca617f9d91a24 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 22 Oct 2018 21:05:59 -0700 Subject: [PATCH] Fix compilation with older gcc --- CMakeLists.txt | 2 +- include/fmt/format-inl.h | 17 +++++++++-------- include/fmt/format.h | 27 ++++++++++++++++----------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 260aa265..7cf74829 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ include(CheckCXXCompilerFlag) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic - -Wold-style-cast -Wlogical-op -Wundef + -Wold-style-cast -Wundef -Wredundant-decls -Wshadow -Wwrite-strings -Wpointer-arith -Wcast-qual -Wformat=2 -Wmissing-include-dirs -Wcast-align -Wnon-virtual-dtor diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index df8f6424..731ad1ad 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -603,6 +603,15 @@ FMT_FUNC void write_exponent(int exp, Handler &&h) { } } +struct fill { + size_t n; + void operator()(char *buffer) const { + buffer[0] = '0'; + buffer[1] = '.'; + std::uninitialized_fill_n(buffer + 2, n, '0'); + } +}; + // The number is given as v = f * pow(10, exp), where f has size digits. template FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, @@ -642,14 +651,6 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, } } else { // 1234e-6 -> 0.001234 - struct fill { - size_t n; - void operator()(char *buffer) const { - buffer[0] = '0'; - buffer[1] = '.'; - std::uninitialized_fill_n(buffer + 2, n, '0'); - } - }; handler.insert(0, 2 - full_exp, fill{to_unsigned(-full_exp)}); } } diff --git a/include/fmt/format.h b/include/fmt/format.h index 15218040..428e4a29 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1779,8 +1779,9 @@ struct arg_ref { FMT_CONSTEXPR arg_ref() : kind(NONE), index(0) {} FMT_CONSTEXPR explicit arg_ref(unsigned index) : kind(INDEX), index(index) {} - explicit arg_ref(basic_string_view name) - : kind(NAME), name{name.data(), name.size()} {} + explicit arg_ref(basic_string_view nm) : kind(NAME) { + name = {nm.data(), nm.size()}; + } FMT_CONSTEXPR arg_ref &operator=(unsigned idx) { kind = INDEX; @@ -3401,24 +3402,27 @@ struct format_to_n_result { }; template -using format_to_n_context = typename fmt::format_context_t< - fmt::internal::truncating_iterator, Char>::type; +struct format_to_n_context : + format_context_t, Char> {}; template -using format_to_n_args = - fmt::basic_format_args>; +struct format_to_n_args { + typedef basic_format_args< + typename format_to_n_context::type> type; +}; template -inline format_arg_store, Args...> +inline format_arg_store< + typename format_to_n_context::type, Args...> make_format_to_n_args(const Args &... args) { return format_arg_store< - format_to_n_context, Args...>(args...); + typename format_to_n_context::type, Args...>(args...); } template inline format_to_n_result vformat_to_n( OutputIt out, std::size_t n, basic_string_view format_str, - format_to_n_args args) { + typename format_to_n_args::type args) { typedef internal::truncating_iterator It; auto it = vformat_to(It(out, n), format_str, args); return {it.base(), it.count()}; @@ -3437,9 +3441,10 @@ inline FMT_ENABLE_IF_STRING(S, format_to_n_result) const Args &... args) { internal::check_format_string(format_str); typedef FMT_CHAR(S) Char; - format_arg_store, Args...> as(args...); + format_arg_store< + typename format_to_n_context::type, Args...> as(args...); return vformat_to_n(out, n, to_string_view(format_str), - format_to_n_args(as)); + typename format_to_n_args::type(as)); } template