Fix compilation with older gcc

This commit is contained in:
Victor Zverovich 2018-10-22 21:05:59 -07:00
parent 1ec0272303
commit 2d2326a76d
3 changed files with 26 additions and 20 deletions

View File

@ -68,7 +68,7 @@ include(CheckCXXCompilerFlag)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic 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 -Wredundant-decls -Wshadow -Wwrite-strings -Wpointer-arith
-Wcast-qual -Wformat=2 -Wmissing-include-dirs -Wcast-qual -Wformat=2 -Wmissing-include-dirs
-Wcast-align -Wnon-virtual-dtor -Wcast-align -Wnon-virtual-dtor

View File

@ -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. // The number is given as v = f * pow(10, exp), where f has size digits.
template <typename Handler> template <typename Handler>
FMT_FUNC void grisu2_prettify(const gen_digits_params &params, FMT_FUNC void grisu2_prettify(const gen_digits_params &params,
@ -642,14 +651,6 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params &params,
} }
} else { } else {
// 1234e-6 -> 0.001234 // 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)}); handler.insert(0, 2 - full_exp, fill{to_unsigned(-full_exp)});
} }
} }

View File

@ -1779,8 +1779,9 @@ struct arg_ref {
FMT_CONSTEXPR arg_ref() : kind(NONE), index(0) {} FMT_CONSTEXPR arg_ref() : kind(NONE), index(0) {}
FMT_CONSTEXPR explicit arg_ref(unsigned index) : kind(INDEX), index(index) {} FMT_CONSTEXPR explicit arg_ref(unsigned index) : kind(INDEX), index(index) {}
explicit arg_ref(basic_string_view<Char> name) explicit arg_ref(basic_string_view<Char> nm) : kind(NAME) {
: kind(NAME), name{name.data(), name.size()} {} name = {nm.data(), nm.size()};
}
FMT_CONSTEXPR arg_ref &operator=(unsigned idx) { FMT_CONSTEXPR arg_ref &operator=(unsigned idx) {
kind = INDEX; kind = INDEX;
@ -3401,24 +3402,27 @@ struct format_to_n_result {
}; };
template <typename OutputIt, typename Char = typename OutputIt::value_type> template <typename OutputIt, typename Char = typename OutputIt::value_type>
using format_to_n_context = typename fmt::format_context_t< struct format_to_n_context :
fmt::internal::truncating_iterator<OutputIt>, Char>::type; format_context_t<fmt::internal::truncating_iterator<OutputIt>, Char> {};
template <typename OutputIt, typename Char = typename OutputIt::value_type> template <typename OutputIt, typename Char = typename OutputIt::value_type>
using format_to_n_args = struct format_to_n_args {
fmt::basic_format_args<format_to_n_context<OutputIt, Char>>; typedef basic_format_args<
typename format_to_n_context<OutputIt, Char>::type> type;
};
template <typename OutputIt, typename Char, typename ...Args> template <typename OutputIt, typename Char, typename ...Args>
inline format_arg_store<format_to_n_context<OutputIt, Char>, Args...> inline format_arg_store<
typename format_to_n_context<OutputIt, Char>::type, Args...>
make_format_to_n_args(const Args &... args) { make_format_to_n_args(const Args &... args) {
return format_arg_store< return format_arg_store<
format_to_n_context<OutputIt, Char>, Args...>(args...); typename format_to_n_context<OutputIt, Char>::type, Args...>(args...);
} }
template <typename OutputIt, typename Char, typename... Args> template <typename OutputIt, typename Char, typename... Args>
inline format_to_n_result<OutputIt> vformat_to_n( inline format_to_n_result<OutputIt> vformat_to_n(
OutputIt out, std::size_t n, basic_string_view<Char> format_str, OutputIt out, std::size_t n, basic_string_view<Char> format_str,
format_to_n_args<OutputIt, Char> args) { typename format_to_n_args<OutputIt, Char>::type args) {
typedef internal::truncating_iterator<OutputIt> It; typedef internal::truncating_iterator<OutputIt> It;
auto it = vformat_to(It(out, n), format_str, args); auto it = vformat_to(It(out, n), format_str, args);
return {it.base(), it.count()}; return {it.base(), it.count()};
@ -3437,9 +3441,10 @@ inline FMT_ENABLE_IF_STRING(S, format_to_n_result<OutputIt>)
const Args &... args) { const Args &... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef FMT_CHAR(S) Char; typedef FMT_CHAR(S) Char;
format_arg_store<format_to_n_context<OutputIt, Char>, Args...> as(args...); format_arg_store<
typename format_to_n_context<OutputIt, Char>::type, Args...> as(args...);
return vformat_to_n(out, n, to_string_view(format_str), return vformat_to_n(out, n, to_string_view(format_str),
format_to_n_args<OutputIt, Char>(as)); typename format_to_n_args<OutputIt, Char>::type(as));
} }
template <typename Char> template <typename Char>