Skip to content

Commit 7ba9ae3

Browse files
committed
Update fmt-12.1.0
1 parent 593cb1d commit 7ba9ae3

10 files changed

Lines changed: 168 additions & 119 deletions

File tree

third_party/fmt/include/fmt/base.h

Lines changed: 25 additions & 9 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 120000
24+
#define FMT_VERSION 120100
2525

2626
// Detect compiler versions.
2727
#if defined(__clang__) && !defined(__ibmxl__)
@@ -114,7 +114,9 @@
114114
#endif
115115

116116
// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated.
117-
#if !defined(__cpp_lib_is_constant_evaluated)
117+
#ifdef FMT_USE_CONSTEVAL
118+
// Use the provided definition.
119+
#elif !defined(__cpp_lib_is_constant_evaluated)
118120
# define FMT_USE_CONSTEVAL 0
119121
#elif FMT_CPLUSPLUS < 201709L
120122
# define FMT_USE_CONSTEVAL 0
@@ -234,6 +236,7 @@ FMT_PRAGMA_GCC(optimize("Og"))
234236
# define FMT_GCC_OPTIMIZED
235237
#endif
236238
FMT_PRAGMA_CLANG(diagnostic push)
239+
FMT_PRAGMA_GCC(diagnostic push)
237240

238241
#ifdef FMT_ALWAYS_INLINE
239242
// Use the provided definition.
@@ -414,8 +417,12 @@ inline auto map(int128_opt) -> monostate { return {}; }
414417
inline auto map(uint128_opt) -> monostate { return {}; }
415418
#endif
416419

417-
#ifndef FMT_USE_BITINT
418-
# define FMT_USE_BITINT (FMT_CLANG_VERSION >= 1500)
420+
#ifdef FMT_USE_BITINT
421+
// Use the provided definition.
422+
#elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
423+
# define FMT_USE_BITINT 1
424+
#else
425+
# define FMT_USE_BITINT 0
419426
#endif
420427

421428
#if FMT_USE_BITINT
@@ -918,7 +925,10 @@ class locale_ref {
918925
constexpr locale_ref() : locale_(nullptr) {}
919926

920927
template <typename Locale, FMT_ENABLE_IF(sizeof(Locale::collate) != 0)>
921-
locale_ref(const Locale& loc);
928+
locale_ref(const Locale& loc) : locale_(&loc) {
929+
// Check if std::isalpha is found via ADL to reduce the chance of misuse.
930+
isalpha('x', loc);
931+
}
922932

923933
inline explicit operator bool() const noexcept { return locale_ != nullptr; }
924934
#endif // FMT_USE_LOCALE
@@ -1844,12 +1854,17 @@ template <typename T> class buffer {
18441854
void
18451855
append(const U* begin, const U* end) {
18461856
while (begin != end) {
1857+
auto size = size_;
1858+
auto free_cap = capacity_ - size;
18471859
auto count = to_unsigned(end - begin);
1848-
try_reserve(size_ + count);
1849-
auto free_cap = capacity_ - size_;
1850-
if (free_cap < count) count = free_cap;
1860+
if (free_cap < count) {
1861+
grow_(*this, size + count);
1862+
size = size_;
1863+
free_cap = capacity_ - size;
1864+
count = count < free_cap ? count : free_cap;
1865+
}
18511866
// A loop is faster than memcpy on small sizes.
1852-
T* out = ptr_ + size_;
1867+
T* out = ptr_ + size;
18531868
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
18541869
size_ += count;
18551870
begin += count;
@@ -2983,6 +2998,7 @@ FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
29832998
return fmt::println(stdout, fmt, static_cast<T&&>(args)...);
29842999
}
29853000

3001+
FMT_PRAGMA_GCC(diagnostic pop)
29863002
FMT_PRAGMA_CLANG(diagnostic pop)
29873003
FMT_PRAGMA_GCC(pop_options)
29883004
FMT_END_EXPORT

third_party/fmt/include/fmt/chrono.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,8 +1594,13 @@ class get_locale {
15941594

15951595
public:
15961596
inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) {
1597-
if (localized)
1598-
::new (&locale_) std::locale(loc.template get<std::locale>());
1597+
if (!localized) return;
1598+
ignore_unused(loc);
1599+
::new (&locale_) std::locale(
1600+
#if FMT_USE_LOCALE
1601+
loc.template get<std::locale>()
1602+
#endif
1603+
);
15991604
}
16001605
inline ~get_locale() {
16011606
if (has_locale_) locale_.~locale();

third_party/fmt/include/fmt/color.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ template <typename Char> struct ansi_color_escape {
429429

430430
private:
431431
static constexpr size_t num_emphases = 8;
432-
Char buffer[7u + 4u * num_emphases];
432+
Char buffer[7u + 4u * num_emphases] = {};
433433
size_t size = 0;
434434

435435
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,

third_party/fmt/include/fmt/compile.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
#include "format.h"
1616

1717
FMT_BEGIN_NAMESPACE
18+
FMT_BEGIN_EXPORT
1819

1920
// A compile-time string which is compiled into fast formatting code.
20-
FMT_EXPORT class compiled_string {};
21+
class compiled_string {};
2122

2223
template <typename S>
2324
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
@@ -59,6 +60,8 @@ template <detail::fixed_string Str> constexpr auto operator""_cf() {
5960
} // namespace literals
6061
#endif
6162

63+
FMT_END_EXPORT
64+
6265
namespace detail {
6366

6467
template <typename T, typename... Tail>

third_party/fmt/include/fmt/format-inl.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ FMT_BEGIN_NAMESPACE
3636
FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
3737
// Use unchecked std::fprintf to avoid triggering another assertion when
3838
// writing to stderr fails.
39-
fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
39+
std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
4040
abort();
4141
}
4242
#endif
@@ -47,11 +47,6 @@ using std::locale;
4747
using std::numpunct;
4848
using std::use_facet;
4949
} // namespace detail
50-
51-
template <typename Locale, enable_if_t<(sizeof(Locale::collate) != 0), int>>
52-
locale_ref::locale_ref(const Locale& loc) : locale_(&loc) {
53-
static_assert(std::is_same<Locale, std::locale>::value, "");
54-
}
5550
#else
5651
namespace detail {
5752
struct locale {};

third_party/fmt/include/fmt/format.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@
4040

4141
#include "base.h"
4242

43+
// libc++ supports string_view in pre-c++17.
44+
#if FMT_HAS_INCLUDE(<string_view>) && \
45+
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
46+
# define FMT_USE_STRING_VIEW
47+
#endif
48+
4349
#ifndef FMT_MODULE
50+
# include <stdlib.h> // malloc, free
51+
4452
# include <cmath> // std::signbit
4553
# include <cstddef> // std::byte
4654
# include <cstdint> // uint32_t
47-
# include <cstdlib> // std::malloc, std::free
4855
# include <cstring> // std::memcpy
4956
# include <limits> // std::numeric_limits
5057
# include <new> // std::bad_alloc
@@ -61,11 +68,8 @@
6168
# include <bit> // std::bit_cast
6269
# endif
6370

64-
// libc++ supports string_view in pre-c++17.
65-
# if FMT_HAS_INCLUDE(<string_view>) && \
66-
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
71+
# if defined(FMT_USE_STRING_VIEW)
6772
# include <string_view>
68-
# define FMT_USE_STRING_VIEW
6973
# endif
7074

7175
# if FMT_MSC_VERSION
@@ -744,12 +748,12 @@ template <typename T> struct allocator : private std::decay<void> {
744748

745749
auto allocate(size_t n) -> T* {
746750
FMT_ASSERT(n <= max_value<size_t>() / sizeof(T), "");
747-
T* p = static_cast<T*>(std::malloc(n * sizeof(T)));
751+
T* p = static_cast<T*>(malloc(n * sizeof(T)));
748752
if (!p) FMT_THROW(std::bad_alloc());
749753
return p;
750754
}
751755

752-
void deallocate(T* p, size_t) { std::free(p); }
756+
void deallocate(T* p, size_t) { free(p); }
753757

754758
constexpr friend auto operator==(allocator, allocator) noexcept -> bool {
755759
return true; // All instances of this allocator are equivalent.
@@ -759,6 +763,14 @@ template <typename T> struct allocator : private std::decay<void> {
759763
}
760764
};
761765

766+
template <typename Formatter>
767+
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set)
768+
-> decltype(f.set_debug_format(set)) {
769+
f.set_debug_format(set);
770+
}
771+
template <typename Formatter>
772+
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {}
773+
762774
} // namespace detail
763775

764776
FMT_BEGIN_EXPORT
@@ -2506,7 +2518,7 @@ FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f,
25062518
auto grouping = Grouping(loc, specs.localized());
25072519
size += grouping.count_separators(exp);
25082520
return write_padded<Char, align::right>(
2509-
out, specs, to_unsigned(size), [&](iterator it) {
2521+
out, specs, static_cast<size_t>(size), [&](iterator it) {
25102522
if (s != sign::none) *it++ = detail::getsign<Char>(s);
25112523
it = write_significand<Char>(it, f.significand, significand_size,
25122524
f.exponent, grouping);

third_party/fmt/include/fmt/os.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ FMT_API std::system_error vwindows_error(int error_code, string_view fmt,
136136
* **Example**:
137137
*
138138
* // This throws a system_error with the description
139-
* // cannot open file 'madeup': The system cannot find the file
140-
* specified.
141-
* // or similar (system message may vary).
142-
* const char *filename = "madeup";
139+
* // cannot open file 'foo': The system cannot find the file specified.
140+
* // or similar (system message may vary) if the file doesn't exist.
141+
* const char *filename = "foo";
143142
* LPOFSTRUCT of = LPOFSTRUCT();
144143
* HFILE file = OpenFile(filename, &of, OF_READ);
145144
* if (file == HFILE_ERROR) {
@@ -365,17 +364,17 @@ FMT_INLINE_VARIABLE constexpr auto buffer_size = detail::buffer_size();
365364

366365
/// A fast buffered output stream for writing from a single thread. Writing from
367366
/// multiple threads without external synchronization may result in a data race.
368-
class FMT_API ostream : private detail::buffer<char> {
367+
class ostream : private detail::buffer<char> {
369368
private:
370369
file file_;
371370

372-
ostream(cstring_view path, const detail::ostream_params& params);
371+
FMT_API ostream(cstring_view path, const detail::ostream_params& params);
373372

374-
static void grow(buffer<char>& buf, size_t);
373+
FMT_API static void grow(buffer<char>& buf, size_t);
375374

376375
public:
377-
ostream(ostream&& other) noexcept;
378-
~ostream();
376+
FMT_API ostream(ostream&& other) noexcept;
377+
FMT_API ~ostream();
379378

380379
operator writer() {
381380
detail::buffer<char>& buf = *this;

third_party/fmt/include/fmt/ranges.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
#include "format.h"
2020

21+
#if FMT_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
22+
# define FMT_LIFETIMEBOUND [[clang::lifetimebound]]
23+
#else
24+
# define FMT_LIFETIMEBOUND
25+
#endif
26+
FMT_PRAGMA_CLANG(diagnostic error "-Wreturn-stack-address")
27+
2128
FMT_BEGIN_NAMESPACE
2229

2330
FMT_EXPORT
@@ -234,14 +241,6 @@ using range_reference_type =
234241
template <typename Range>
235242
using uncvref_type = remove_cvref_t<range_reference_type<Range>>;
236243

237-
template <typename Formatter>
238-
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set)
239-
-> decltype(f.set_debug_format(set)) {
240-
f.set_debug_format(set);
241-
}
242-
template <typename Formatter>
243-
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {}
244-
245244
template <typename T>
246245
struct range_format_kind_
247246
: std::integral_constant<range_format,
@@ -821,12 +820,12 @@ auto join(Range&& r, string_view sep)
821820
*
822821
* **Example**:
823822
*
824-
* auto t = std::tuple<int, char>{1, 'a'};
823+
* auto t = std::tuple<int, char>(1, 'a');
825824
* fmt::print("{}", fmt::join(t, ", "));
826825
* // Output: 1, a
827826
*/
828827
template <typename Tuple, FMT_ENABLE_IF(is_tuple_like<Tuple>::value)>
829-
FMT_CONSTEXPR auto join(const Tuple& tuple, string_view sep)
828+
FMT_CONSTEXPR auto join(const Tuple& tuple FMT_LIFETIMEBOUND, string_view sep)
830829
-> tuple_join_view<Tuple, char> {
831830
return {tuple, sep};
832831
}

0 commit comments

Comments
 (0)