From 175741ed1dab4ac9b048b5b82fb340b418741310 Mon Sep 17 00:00:00 2001 From: gabime Date: Thu, 12 Dec 2019 23:50:30 +0200 Subject: [PATCH 1/2] Bump fmt to 6.1.2 --- include/spdlog/fmt/bundled/chrono.h | 11 +++-- include/spdlog/fmt/bundled/compile.h | 12 +++--- include/spdlog/fmt/bundled/core.h | 20 +++++---- include/spdlog/fmt/bundled/format.h | 61 ++-------------------------- include/spdlog/fmt/bundled/printf.h | 30 +++++++------- include/spdlog/fmt/fmt.h | 14 +------ src/fmt.cpp | 13 ------ 7 files changed, 43 insertions(+), 118 deletions(-) diff --git a/include/spdlog/fmt/bundled/chrono.h b/include/spdlog/fmt/bundled/chrono.h index 9abe7c4f..ca4ed30a 100644 --- a/include/spdlog/fmt/bundled/chrono.h +++ b/include/spdlog/fmt/bundled/chrono.h @@ -696,7 +696,7 @@ inline int to_nonnegative_int(T value, int upper) { template ::value)> inline T mod(T x, int y) { - return x % y; + return x % static_cast(y); } template ::value)> inline T mod(T x, int y) { @@ -793,7 +793,10 @@ struct chrono_formatter { explicit chrono_formatter(FormatContext& ctx, OutputIt o, std::chrono::duration d) - : context(ctx), out(o), val(d.count()), negative(false) { + : context(ctx), + out(o), + val(static_cast(d.count())), + negative(false) { if (d.count() < 0) { val = 0 - val; negative = true; @@ -1023,8 +1026,8 @@ struct formatter, Char> { void on_error(const char* msg) { FMT_THROW(format_error(msg)); } void on_fill(Char fill) { f.specs.fill[0] = fill; } void on_align(align_t align) { f.specs.align = align; } - void on_width(unsigned width) { f.specs.width = width; } - void on_precision(unsigned _precision) { f.precision = _precision; } + void on_width(int width) { f.specs.width = width; } + void on_precision(int _precision) { f.precision = _precision; } void end_precision() {} template void on_dynamic_width(Id arg_id) { diff --git a/include/spdlog/fmt/bundled/compile.h b/include/spdlog/fmt/bundled/compile.h index f65f5a74..5829f623 100644 --- a/include/spdlog/fmt/bundled/compile.h +++ b/include/spdlog/fmt/bundled/compile.h @@ -26,11 +26,11 @@ template struct format_part { kind part_kind; union value { - unsigned arg_index; + int arg_index; basic_string_view str; replacement repl; - FMT_CONSTEXPR value(unsigned index = 0) : arg_index(index) {} + FMT_CONSTEXPR value(int index = 0) : arg_index(index) {} FMT_CONSTEXPR value(basic_string_view s) : str(s) {} FMT_CONSTEXPR value(replacement r) : repl(r) {} } val; @@ -40,7 +40,7 @@ template struct format_part { FMT_CONSTEXPR format_part(kind k = kind::arg_index, value v = {}) : part_kind(k), val(v) {} - static FMT_CONSTEXPR format_part make_arg_index(unsigned index) { + static FMT_CONSTEXPR format_part make_arg_index(int index) { return format_part(kind::arg_index, index); } static FMT_CONSTEXPR format_part make_arg_name(basic_string_view name) { @@ -62,7 +62,7 @@ template struct part_counter { } FMT_CONSTEXPR void on_arg_id() { ++num_parts; } - FMT_CONSTEXPR void on_arg_id(unsigned) { ++num_parts; } + FMT_CONSTEXPR void on_arg_id(int) { ++num_parts; } FMT_CONSTEXPR void on_arg_id(basic_string_view) { ++num_parts; } FMT_CONSTEXPR void on_replacement_field(const Char*) {} @@ -119,7 +119,7 @@ class format_string_compiler : public error_handler { part_ = part::make_arg_index(parse_context_.next_arg_id()); } - FMT_CONSTEXPR void on_arg_id(unsigned id) { + FMT_CONSTEXPR void on_arg_id(int id) { parse_context_.check_arg_id(id); part_ = part::make_arg_index(id); } @@ -512,8 +512,6 @@ template ::value)> std::basic_string format(const CompiledFormat& cf, const Args&... args) { basic_memory_buffer buffer; - using range = buffer_range; - using context = buffer_context; cf.format(std::back_inserter(buffer), args...); return to_string(buffer); } diff --git a/include/spdlog/fmt/bundled/core.h b/include/spdlog/fmt/bundled/core.h index 13d74ba8..9fd8df28 100644 --- a/include/spdlog/fmt/bundled/core.h +++ b/include/spdlog/fmt/bundled/core.h @@ -15,7 +15,7 @@ #include // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 60101 +#define FMT_VERSION 60102 #ifdef __has_feature # define FMT_HAS_FEATURE(x) __has_feature(x) @@ -878,7 +878,7 @@ template struct arg_mapper { FMT_ENABLE_IF( std::is_constructible, T>::value && !std::is_constructible, T>::value && - !is_string::value)> + !is_string::value && !has_formatter::value)> FMT_CONSTEXPR basic_string_view map(const T& val) { return std_string_view(val); } @@ -911,12 +911,14 @@ template struct arg_mapper { map(static_cast::type>(val))) { return map(static_cast::type>(val)); } - template ::value && !is_char::value && - !std::is_constructible, - T>::value && - (has_formatter::value || - has_fallback_formatter::value))> + template < + typename T, + FMT_ENABLE_IF( + !is_string::value && !is_char::value && + !std::is_constructible, T>::value && + (has_formatter::value || + (has_fallback_formatter::value && + !std::is_constructible, T>::value)))> FMT_CONSTEXPR const T& map(const T& val) { return val; } @@ -1283,7 +1285,7 @@ template class basic_format_args { */ template basic_format_args(const format_arg_store& store) - : types_(static_cast(store.types)) { + : types_(store.types) { set_data(store.data_); } diff --git a/include/spdlog/fmt/bundled/format.h b/include/spdlog/fmt/bundled/format.h index 600b0eba..01f41f5c 100644 --- a/include/spdlog/fmt/bundled/format.h +++ b/include/spdlog/fmt/bundled/format.h @@ -69,7 +69,8 @@ # define FMT_HAS_BUILTIN(x) 0 #endif -#if FMT_HAS_CPP_ATTRIBUTE(fallthrough) >= 201603 && __cplusplus >= 201703 +#if FMT_HAS_CPP_ATTRIBUTE(fallthrough) && \ + (__cplusplus >= 201703 || FMT_GCC_VERSION != 0) # define FMT_FALLTHROUGH [[fallthrough]] #else # define FMT_FALLTHROUGH @@ -801,60 +802,6 @@ template <> int count_digits<4>(internal::fallback_uintptr n); # define FMT_ALWAYS_INLINE #endif -// Computes g = floor(log10(n)) and calls h.on(n); -template FMT_ALWAYS_INLINE char* lg(uint32_t n, Handler h) { - return n < 100 ? n < 10 ? h.template on<0>(n) : h.template on<1>(n) - : n < 1000000 - ? n < 10000 ? n < 1000 ? h.template on<2>(n) - : h.template on<3>(n) - : n < 100000 ? h.template on<4>(n) - : h.template on<5>(n) - : n < 100000000 ? n < 10000000 ? h.template on<6>(n) - : h.template on<7>(n) - : n < 1000000000 ? h.template on<8>(n) - : h.template on<9>(n); -} - -// An lg handler that formats a decimal number. -// Usage: lg(n, decimal_formatter(buffer)); -class decimal_formatter { - private: - char* buffer_; - - void write_pair(unsigned N, uint32_t index) { - std::memcpy(buffer_ + N, data::digits + index * 2, 2); - } - - public: - explicit decimal_formatter(char* buf) : buffer_(buf) {} - - template char* on(uint32_t u) { - if (N == 0) { - *buffer_ = static_cast(u) + '0'; - } else if (N == 1) { - write_pair(0, u); - } else { - // The idea of using 4.32 fixed-point numbers is based on - // https://github.com/jeaiii/itoa - unsigned n = N - 1; - unsigned a = n / 5 * n * 53 / 16; - uint64_t t = - ((1ULL << (32 + a)) / data::zero_or_powers_of_10_32[n] + 1 - n / 9); - t = ((t * u) >> a) + n / 5 * 4; - write_pair(0, t >> 32); - for (unsigned i = 2; i < N; i += 2) { - t = 100ULL * static_cast(t); - write_pair(i, t >> 32); - } - if (N % 2 == 0) { - buffer_[N] = - static_cast((10ULL * static_cast(t)) >> 32) + '0'; - } - } - return buffer_ += N + 1; - } -}; - #ifdef FMT_BUILTIN_CLZ // Optional version of count_digits for better performance on 32-bit platforms. inline int count_digits(uint32_t n) { @@ -2620,7 +2567,7 @@ class format_string_checker { public: explicit FMT_CONSTEXPR format_string_checker( basic_string_view format_str, ErrorHandler eh) - : arg_id_(max_value()), + : arg_id_(-1), context_(format_str, eh), parse_funcs_{&parse_format_specs...} {} @@ -2661,7 +2608,7 @@ class format_string_checker { // Format specifier parsing function. using parse_func = const Char* (*)(parse_context_type&); - unsigned arg_id_; + int arg_id_; parse_context_type context_; parse_func parse_funcs_[num_args > 0 ? num_args : 1]; }; diff --git a/include/spdlog/fmt/bundled/printf.h b/include/spdlog/fmt/bundled/printf.h index cdbb65e6..a2fa945d 100644 --- a/include/spdlog/fmt/bundled/printf.h +++ b/include/spdlog/fmt/bundled/printf.h @@ -333,12 +333,12 @@ template class basic_printf_context { static void parse_flags(format_specs& specs, const Char*& it, const Char* end); - // Returns the argument with specified index or, if arg_index is equal - // to the maximum unsigned value, the next argument. - format_arg get_arg(unsigned arg_index = internal::max_value()); + // Returns the argument with specified index or, if arg_index is -1, the next + // argument. + format_arg get_arg(int arg_index = -1); // Parses argument index, flags and width and returns the argument index. - unsigned parse_header(const Char*& it, const Char* end, format_specs& specs); + int parse_header(const Char*& it, const Char* end, format_specs& specs); public: /** @@ -355,7 +355,7 @@ template class basic_printf_context { OutputIt out() { return out_; } void advance_to(OutputIt it) { out_ = it; } - format_arg arg(unsigned id) const { return args_.get(id); } + format_arg arg(int id) const { return args_.get(id); } basic_format_parse_context& parse_context() { return parse_ctx_; } @@ -397,8 +397,8 @@ void basic_printf_context::parse_flags(format_specs& specs, template typename basic_printf_context::format_arg -basic_printf_context::get_arg(unsigned arg_index) { - if (arg_index == internal::max_value()) +basic_printf_context::get_arg(int arg_index) { + if (arg_index < 0) arg_index = parse_ctx_.next_arg_id(); else parse_ctx_.check_arg_id(--arg_index); @@ -406,15 +406,15 @@ basic_printf_context::get_arg(unsigned arg_index) { } template -unsigned basic_printf_context::parse_header( +int basic_printf_context::parse_header( const Char*& it, const Char* end, format_specs& specs) { - unsigned arg_index = internal::max_value(); + int arg_index = -1; char_type c = *it; if (c >= '0' && c <= '9') { // Parse an argument index (if followed by '$') or a width possibly // preceded with '0' flag(s). internal::error_handler eh; - unsigned value = parse_nonnegative_int(it, end, eh); + int value = parse_nonnegative_int(it, end, eh); if (it != end && *it == '$') { // value is an argument index ++it; arg_index = value; @@ -436,8 +436,8 @@ unsigned basic_printf_context::parse_header( specs.width = parse_nonnegative_int(it, end, eh); } else if (*it == '*') { ++it; - specs.width = visit_format_arg( - internal::printf_width_handler(specs), get_arg()); + specs.width = static_cast(visit_format_arg( + internal::printf_width_handler(specs), get_arg())); } } return arg_index; @@ -464,7 +464,7 @@ OutputIt basic_printf_context::format() { specs.align = align::right; // Parse argument index, flags and width. - unsigned arg_index = parse_header(it, end, specs); + int arg_index = parse_header(it, end, specs); if (arg_index == 0) on_error("argument index out of range"); // Parse precision. @@ -473,11 +473,11 @@ OutputIt basic_printf_context::format() { c = it != end ? *it : 0; if ('0' <= c && c <= '9') { internal::error_handler eh; - specs.precision = static_cast(parse_nonnegative_int(it, end, eh)); + specs.precision = parse_nonnegative_int(it, end, eh); } else if (c == '*') { ++it; specs.precision = - visit_format_arg(internal::printf_precision_handler(), get_arg()); + static_cast(visit_format_arg(internal::printf_precision_handler(), get_arg())); } else { specs.precision = 0; } diff --git a/include/spdlog/fmt/fmt.h b/include/spdlog/fmt/fmt.h index c426e2b2..289979aa 100644 --- a/include/spdlog/fmt/fmt.h +++ b/include/spdlog/fmt/fmt.h @@ -10,13 +10,6 @@ // By default spdlog include its own copy. // -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#endif // __GNUC__ || __clang__ - - #if !defined(SPDLOG_FMT_EXTERNAL) #ifdef SPDLOG_HEADER_ONLY #ifndef FMT_HEADER_ONLY @@ -31,9 +24,4 @@ #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib #include #include -#endif - -// pop warnings supressions -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif +#endif \ No newline at end of file diff --git a/src/fmt.cpp b/src/fmt.cpp index 431b2a57..4a1b106e 100644 --- a/src/fmt.cpp +++ b/src/fmt.cpp @@ -6,22 +6,9 @@ // Copyright (c) 2012 - 2016, Victor Zverovich // All rights reserved. -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#endif - #if !defined(SPDLOG_FMT_EXTERNAL) #include "spdlog/fmt/bundled/format-inl.h" - -// pop warnings supressions -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - - FMT_BEGIN_NAMESPACE template struct FMT_API internal::basic_data; From ebaa16f403db02d847feb6a6a9c926bad5dd77be Mon Sep 17 00:00:00 2001 From: gabime Date: Thu, 12 Dec 2019 23:52:22 +0200 Subject: [PATCH 2/2] CMakeLists.txt allow overriding the cpp standard to higher than 11 --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 260f8ae2..508a0b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,11 @@ message(STATUS "Build spdlog: ${SPDLOG_VERSION}") #--------------------------------------------------------------------------------------- # Compiler config #--------------------------------------------------------------------------------------- -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() + set(CMAKE_CXX_EXTENSIONS OFF) if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")