Skip to content

Commit f1fe6e9

Browse files
Merge branch 'gabime:v1.x' into v1.x
2 parents 3681f32 + faa0a7a commit f1fe6e9

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

include/spdlog/fmt/bundled/base.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#endif
2222

2323
// The fmt library version in the form major * 10000 + minor * 100 + patch.
24-
#define FMT_VERSION 110103
24+
#define FMT_VERSION 110104
2525

2626
// Detect compiler versions.
2727
#if defined(__clang__) && !defined(__ibmxl__)
@@ -295,8 +295,8 @@
295295
#endif
296296

297297
#define FMT_APPLY_VARIADIC(expr) \
298-
using ignore = int[]; \
299-
(void)ignore { 0, (expr, 0)... }
298+
using unused = int[]; \
299+
(void)unused { 0, (expr, 0)... }
300300

301301
// Enable minimal optimizations for more compact code in debug mode.
302302
FMT_PRAGMA_GCC(push_options)
@@ -538,7 +538,7 @@ template <typename Char> class basic_string_view {
538538
FMT_ALWAYS_INLINE
539539
#endif
540540
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
541-
#if FMT_HAS_BUILTIN(__buitin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
541+
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
542542
if (std::is_same<Char, char>::value) {
543543
size_ = __builtin_strlen(detail::narrow(s));
544544
return;
@@ -741,7 +741,7 @@ class basic_specs {
741741
};
742742

743743
unsigned data_ = 1 << fill_size_shift;
744-
static_assert(sizeof(data_) * CHAR_BIT >= 18, "");
744+
static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, "");
745745

746746
// Character (code unit) type is erased to prevent template bloat.
747747
char fill_data_[max_fill_size] = {' '};
@@ -2264,15 +2264,15 @@ template <> struct is_output_iterator<appender, char> : std::true_type {};
22642264
template <typename It, typename T>
22652265
struct is_output_iterator<
22662266
It, T,
2267-
void_t<decltype(*std::declval<decay_t<It>&>()++ = std::declval<T>())>>
2268-
: std::true_type {};
2267+
enable_if_t<std::is_assignable<decltype(*std::declval<decay_t<It>&>()++),
2268+
T>::value>> : std::true_type {};
22692269

22702270
#ifndef FMT_USE_LOCALE
22712271
# define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1)
22722272
#endif
22732273

22742274
// A type-erased reference to an std::locale to avoid a heavy <locale> include.
2275-
struct locale_ref {
2275+
class locale_ref {
22762276
#if FMT_USE_LOCALE
22772277
private:
22782278
const void* locale_; // A type-erased pointer to std::locale.
@@ -2284,6 +2284,7 @@ struct locale_ref {
22842284
inline explicit operator bool() const noexcept { return locale_ != nullptr; }
22852285
#endif // FMT_USE_LOCALE
22862286

2287+
public:
22872288
template <typename Locale> auto get() const -> Locale;
22882289
};
22892290

@@ -2730,9 +2731,9 @@ template <typename... T> struct fstring {
27302731
std::is_same<typename S::char_type, char>::value)>
27312732
FMT_ALWAYS_INLINE fstring(const S&) : str(S()) {
27322733
FMT_CONSTEXPR auto sv = string_view(S());
2733-
FMT_CONSTEXPR int ignore =
2734+
FMT_CONSTEXPR int unused =
27342735
(parse_format_string(sv, checker(sv, arg_pack())), 0);
2735-
detail::ignore_unused(ignore);
2736+
detail::ignore_unused(unused);
27362737
}
27372738
fstring(runtime_format_string<> fmt) : str(fmt.str) {}
27382739

include/spdlog/fmt/bundled/compile.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ FMT_BEGIN_NAMESPACE
1919
// A compile-time string which is compiled into fast formatting code.
2020
FMT_EXPORT class compiled_string {};
2121

22-
namespace detail {
23-
2422
template <typename S>
2523
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
2624

25+
namespace detail {
26+
2727
/**
2828
* Converts a string literal `s` into a format string that will be parsed at
2929
* compile time and converted into efficient formatting code. Requires C++17
@@ -41,16 +41,6 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
4141
# define FMT_COMPILE(s) FMT_STRING(s)
4242
#endif
4343

44-
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
45-
template <typename Char, size_t N, fmt::detail::fixed_string<Char, N> Str>
46-
struct udl_compiled_string : compiled_string {
47-
using char_type = Char;
48-
constexpr explicit operator basic_string_view<char_type>() const {
49-
return {Str.data, N - 1};
50-
}
51-
};
52-
#endif
53-
5444
template <typename T, typename... Tail>
5545
auto first(const T& value, const Tail&...) -> const T& {
5646
return value;
@@ -425,7 +415,7 @@ constexpr auto compile_format_string(S fmt) {
425415
}
426416

427417
template <typename... Args, typename S,
428-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
418+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
429419
constexpr auto compile(S fmt) {
430420
constexpr auto str = basic_string_view<typename S::char_type>(fmt);
431421
if constexpr (str.size() == 0) {
@@ -461,7 +451,7 @@ constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf,
461451
}
462452

463453
template <typename S, typename... Args,
464-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
454+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
465455
FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
466456
Args&&... args) {
467457
if constexpr (std::is_same<typename S::char_type, char>::value) {
@@ -488,7 +478,7 @@ FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
488478
}
489479

490480
template <typename OutputIt, typename S, typename... Args,
491-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
481+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
492482
FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
493483
constexpr auto compiled = detail::compile<Args...>(S());
494484
if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
@@ -503,7 +493,7 @@ FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
503493
#endif
504494

505495
template <typename OutputIt, typename S, typename... Args,
506-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
496+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
507497
auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
508498
-> format_to_n_result<OutputIt> {
509499
using traits = detail::fixed_buffer_traits;
@@ -513,7 +503,7 @@ auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args)
513503
}
514504

515505
template <typename S, typename... Args,
516-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
506+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
517507
FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
518508
-> size_t {
519509
auto buf = detail::counting_buffer<>();
@@ -522,25 +512,23 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
522512
}
523513

524514
template <typename S, typename... Args,
525-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
515+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
526516
void print(std::FILE* f, const S& fmt, const Args&... args) {
527517
auto buf = memory_buffer();
528518
fmt::format_to(appender(buf), fmt, args...);
529519
detail::print(f, {buf.data(), buf.size()});
530520
}
531521

532522
template <typename S, typename... Args,
533-
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
523+
FMT_ENABLE_IF(is_compiled_string<S>::value)>
534524
void print(const S& fmt, const Args&... args) {
535525
print(stdout, fmt, args...);
536526
}
537527

538528
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
539529
inline namespace literals {
540530
template <detail::fixed_string Str> constexpr auto operator""_cf() {
541-
using char_t = remove_cvref_t<decltype(Str.data[0])>;
542-
return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
543-
Str>();
531+
return FMT_COMPILE(Str.data);
544532
}
545533
} // namespace literals
546534
#endif

include/spdlog/fmt/bundled/format.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ template <typename Char, typename OutputIt, typename DecimalFP,
23322332
typename Grouping = digit_grouping<Char>>
23332333
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
23342334
const format_specs& specs, sign s,
2335-
locale_ref loc) -> OutputIt {
2335+
int exp_upper, locale_ref loc) -> OutputIt {
23362336
auto significand = f.significand;
23372337
int significand_size = get_significand_size(f);
23382338
const Char zero = static_cast<Char>('0');
@@ -2348,7 +2348,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
23482348
if (specs.type() == presentation_type::fixed) return false;
23492349
// Use the fixed notation if the exponent is in [exp_lower, exp_upper),
23502350
// e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation.
2351-
const int exp_lower = -4, exp_upper = 16;
2351+
const int exp_lower = -4;
23522352
return output_exp < exp_lower ||
23532353
output_exp >= (specs.precision > 0 ? specs.precision : exp_upper);
23542354
};
@@ -2451,12 +2451,13 @@ template <typename Char> class fallback_digit_grouping {
24512451
template <typename Char, typename OutputIt, typename DecimalFP>
24522452
FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,
24532453
const format_specs& specs, sign s,
2454-
locale_ref loc) -> OutputIt {
2454+
int exp_upper, locale_ref loc) -> OutputIt {
24552455
if (is_constant_evaluated()) {
24562456
return do_write_float<Char, OutputIt, DecimalFP,
2457-
fallback_digit_grouping<Char>>(out, f, specs, s, loc);
2457+
fallback_digit_grouping<Char>>(out, f, specs, s,
2458+
exp_upper, loc);
24582459
} else {
2459-
return do_write_float<Char>(out, f, specs, s, loc);
2460+
return do_write_float<Char>(out, f, specs, s, exp_upper, loc);
24602461
}
24612462
}
24622463

@@ -3288,6 +3289,14 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision,
32883289
return exp;
32893290
}
32903291

3292+
// Numbers with exponents greater or equal to the returned value will use
3293+
// the exponential notation.
3294+
template <typename T> constexpr auto exp_upper() -> int {
3295+
return std::numeric_limits<T>::digits10 != 0
3296+
? min_of(16, std::numeric_limits<T>::digits10 + 1)
3297+
: 16;
3298+
}
3299+
32913300
template <typename Char, typename OutputIt, typename T>
32923301
FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
32933302
locale_ref loc) -> OutputIt {
@@ -3303,6 +3312,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
33033312
if (specs.width != 0) --specs.width;
33043313
}
33053314

3315+
constexpr int exp_upper = detail::exp_upper<T>();
33063316
int precision = specs.precision;
33073317
if (precision < 0) {
33083318
if (specs.type() != presentation_type::none) {
@@ -3311,7 +3321,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
33113321
// Use Dragonbox for the shortest format.
33123322
using floaty = conditional_t<sizeof(T) >= sizeof(double), double, float>;
33133323
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
3314-
return write_float<Char>(out, dec, specs, s, loc);
3324+
return write_float<Char>(out, dec, specs, s, exp_upper, loc);
33153325
}
33163326
}
33173327

@@ -3339,7 +3349,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs,
33393349

33403350
specs.precision = precision;
33413351
auto f = big_decimal_fp{buffer.data(), static_cast<int>(buffer.size()), exp};
3342-
return write_float<Char>(out, f, specs, s, loc);
3352+
return write_float<Char>(out, f, specs, s, exp_upper, loc);
33433353
}
33443354

33453355
template <typename Char, typename OutputIt, typename T,
@@ -3366,7 +3376,7 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt {
33663376
return write_nonfinite<Char>(out, std::isnan(value), specs, s);
33673377

33683378
auto dec = dragonbox::to_decimal(static_cast<floaty>(value));
3369-
return write_float<Char>(out, dec, specs, s, {});
3379+
return write_float<Char>(out, dec, specs, s, exp_upper<T>(), {});
33703380
}
33713381

33723382
template <typename Char, typename OutputIt, typename T,

include/spdlog/pattern_formatter-inl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class scoped_padder {
7070
pad_it(remaining_pad_);
7171
} else if (padinfo_.truncate_) {
7272
long new_size = static_cast<long>(dest_.size()) + remaining_pad_;
73+
if (new_size < 0) {
74+
new_size = 0;
75+
}
7376
dest_.resize(static_cast<size_t>(new_size));
7477
}
7578
}
@@ -264,7 +267,7 @@ class D_formatter final : public flag_formatter {
264267
: flag_formatter(padinfo) {}
265268

266269
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override {
267-
const size_t field_size = 10;
270+
const size_t field_size = 8;
268271
ScopedPadder p(field_size, padinfo_, dest);
269272

270273
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
@@ -926,9 +929,8 @@ class full_formatter final : public flag_formatter {
926929
memory_buf_t cached_datetime_;
927930

928931
#ifndef SPDLOG_NO_TLS
929-
mdc_formatter<null_scoped_padder> mdc_formatter_{padding_info{}};
932+
mdc_formatter<null_scoped_padder> mdc_formatter_{padding_info {}};
930933
#endif
931-
932934
};
933935

934936
} // namespace details

0 commit comments

Comments
 (0)