Consistently namespace qualify size_t

This commit is contained in:
Victor Zverovich 2020-05-07 15:59:46 -07:00
parent c06851456d
commit 7f723fbcb8
39 changed files with 222 additions and 209 deletions

View File

@ -387,13 +387,13 @@ inline std::tm gmtime(std::time_t time) {
} }
namespace internal { namespace internal {
inline std::size_t strftime(char* str, std::size_t count, const char* format, inline size_t strftime(char* str, size_t count, const char* format,
const std::tm* time) { const std::tm* time) {
return std::strftime(str, count, format, time); return std::strftime(str, count, format, time);
} }
inline std::size_t strftime(wchar_t* str, std::size_t count, inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format,
const wchar_t* format, const std::tm* time) { const std::tm* time) {
return std::wcsftime(str, count, format, time); return std::wcsftime(str, count, format, time);
} }
} // namespace internal } // namespace internal
@ -414,11 +414,10 @@ template <typename Char> struct formatter<std::tm, Char> {
template <typename FormatContext> template <typename FormatContext>
auto format(const std::tm& tm, FormatContext& ctx) -> decltype(ctx.out()) { auto format(const std::tm& tm, FormatContext& ctx) -> decltype(ctx.out()) {
basic_memory_buffer<Char> buf; basic_memory_buffer<Char> buf;
std::size_t start = buf.size(); size_t start = buf.size();
for (;;) { for (;;) {
std::size_t size = buf.capacity() - start; size_t size = buf.capacity() - start;
std::size_t count = size_t count = internal::strftime(&buf[start], size, &tm_format[0], &tm);
internal::strftime(&buf[start], size, &tm_format[0], &tm);
if (count != 0) { if (count != 0) {
buf.resize(start + count); buf.resize(start + count);
break; break;
@ -430,7 +429,7 @@ template <typename Char> struct formatter<std::tm, Char> {
// https://github.com/fmtlib/fmt/issues/367 // https://github.com/fmtlib/fmt/issues/367
break; break;
} }
const std::size_t MIN_GROWTH = 10; const size_t MIN_GROWTH = 10;
buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH)); buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
} }
return std::copy(buf.begin(), buf.end(), ctx.out()); return std::copy(buf.begin(), buf.end(), ctx.out());

View File

@ -364,7 +364,7 @@ template <typename Char> struct ansi_color_escape {
// 10 more. // 10 more.
if (is_background) value += 10u; if (is_background) value += 10u;
std::size_t index = 0; size_t index = 0;
buffer[index++] = static_cast<Char>('\x1b'); buffer[index++] = static_cast<Char>('\x1b');
buffer[index++] = static_cast<Char>('['); buffer[index++] = static_cast<Char>('[');
@ -398,7 +398,7 @@ template <typename Char> struct ansi_color_escape {
if (em_bits & static_cast<uint8_t>(emphasis::strikethrough)) if (em_bits & static_cast<uint8_t>(emphasis::strikethrough))
em_codes[3] = 9; em_codes[3] = 9;
std::size_t index = 0; size_t index = 0;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
if (!em_codes[i]) continue; if (!em_codes[i]) continue;
buffer[index++] = static_cast<Char>('\x1b'); buffer[index++] = static_cast<Char>('\x1b');

View File

@ -586,7 +586,7 @@ format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
} }
template <typename CompiledFormat, typename... Args> template <typename CompiledFormat, typename... Args>
std::size_t formatted_size(const CompiledFormat& cf, const Args&... args) { size_t formatted_size(const CompiledFormat& cf, const Args&... args) {
return format_to(internal::counting_iterator(), cf, args...).count(); return format_to(internal::counting_iterator(), cf, args...).count();
} }

View File

@ -630,27 +630,27 @@ namespace internal {
template <typename T> class buffer { template <typename T> class buffer {
private: private:
T* ptr_; T* ptr_;
std::size_t size_; size_t size_;
std::size_t capacity_; size_t capacity_;
protected: protected:
// Don't initialize ptr_ since it is not accessed to save a few cycles. // Don't initialize ptr_ since it is not accessed to save a few cycles.
FMT_SUPPRESS_MSC_WARNING(26495) FMT_SUPPRESS_MSC_WARNING(26495)
buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT
: ptr_(p), : ptr_(p),
size_(sz), size_(sz),
capacity_(cap) {} capacity_(cap) {}
/** Sets the buffer data and capacity. */ /** Sets the buffer data and capacity. */
void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT { void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT {
ptr_ = buf_data; ptr_ = buf_data;
capacity_ = buf_capacity; capacity_ = buf_capacity;
} }
/** Increases the buffer capacity to hold at least *capacity* elements. */ /** Increases the buffer capacity to hold at least *capacity* elements. */
virtual void grow(std::size_t capacity) = 0; virtual void grow(size_t capacity) = 0;
public: public:
using value_type = T; using value_type = T;
@ -667,10 +667,10 @@ template <typename T> class buffer {
const T* end() const FMT_NOEXCEPT { return ptr_ + size_; } const T* end() const FMT_NOEXCEPT { return ptr_ + size_; }
/** Returns the size of this buffer. */ /** Returns the size of this buffer. */
std::size_t size() const FMT_NOEXCEPT { return size_; } size_t size() const FMT_NOEXCEPT { return size_; }
/** Returns the capacity of this buffer. */ /** Returns the capacity of this buffer. */
std::size_t capacity() const FMT_NOEXCEPT { return capacity_; } size_t capacity() const FMT_NOEXCEPT { return capacity_; }
/** Returns a pointer to the buffer data. */ /** Returns a pointer to the buffer data. */
T* data() FMT_NOEXCEPT { return ptr_; } T* data() FMT_NOEXCEPT { return ptr_; }
@ -681,7 +681,7 @@ template <typename T> class buffer {
/** /**
Resizes the buffer. If T is a POD type new elements may not be initialized. Resizes the buffer. If T is a POD type new elements may not be initialized.
*/ */
void resize(std::size_t new_size) { void resize(size_t new_size) {
reserve(new_size); reserve(new_size);
size_ = new_size; size_ = new_size;
} }
@ -690,7 +690,7 @@ template <typename T> class buffer {
void clear() { size_ = 0; } void clear() { size_ = 0; }
/** Reserves space to store at least *capacity* elements. */ /** Reserves space to store at least *capacity* elements. */
void reserve(std::size_t new_capacity) { void reserve(size_t new_capacity) {
if (new_capacity > capacity_) grow(new_capacity); if (new_capacity > capacity_) grow(new_capacity);
} }
@ -715,7 +715,7 @@ class container_buffer : public buffer<typename Container::value_type> {
Container& container_; Container& container_;
protected: protected:
void grow(std::size_t capacity) FMT_OVERRIDE { void grow(size_t capacity) FMT_OVERRIDE {
container_.resize(capacity); container_.resize(capacity);
this->set(&container_[0], capacity); this->set(&container_[0], capacity);
} }
@ -869,12 +869,12 @@ constexpr bool is_arithmetic_type(type t) {
template <typename Char> struct string_value { template <typename Char> struct string_value {
const Char* data; const Char* data;
std::size_t size; size_t size;
}; };
template <typename Char> struct named_arg_value { template <typename Char> struct named_arg_value {
const named_arg_info<Char>* data; const named_arg_info<Char>* data;
std::size_t size; size_t size;
}; };
template <typename Context> struct custom_value { template <typename Context> struct custom_value {

View File

@ -41,7 +41,7 @@
// Dummy implementations of strerror_r and strerror_s called if corresponding // Dummy implementations of strerror_r and strerror_s called if corresponding
// system functions are not available. // system functions are not available.
inline fmt::internal::null<> strerror_r(int, char*, ...) { return {}; } inline fmt::internal::null<> strerror_r(int, char*, ...) { return {}; }
inline fmt::internal::null<> strerror_s(char*, std::size_t, ...) { return {}; } inline fmt::internal::null<> strerror_s(char*, size_t, ...) { return {}; }
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
@ -76,14 +76,14 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) {
// other - failure // other - failure
// Buffer should be at least of size 1. // Buffer should be at least of size 1.
FMT_FUNC int safe_strerror(int error_code, char*& buffer, FMT_FUNC int safe_strerror(int error_code, char*& buffer,
std::size_t buffer_size) FMT_NOEXCEPT { size_t buffer_size) FMT_NOEXCEPT {
FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer"); FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer");
class dispatcher { class dispatcher {
private: private:
int error_code_; int error_code_;
char*& buffer_; char*& buffer_;
std::size_t buffer_size_; size_t buffer_size_;
// A noop assignment operator to avoid bogus warnings. // A noop assignment operator to avoid bogus warnings.
void operator=(const dispatcher&) {} void operator=(const dispatcher&) {}
@ -128,7 +128,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer,
#endif #endif
public: public:
dispatcher(int err_code, char*& buf, std::size_t buf_size) dispatcher(int err_code, char*& buf, size_t buf_size)
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); } int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); }
@ -145,7 +145,7 @@ FMT_FUNC void format_error_code(internal::buffer<char>& out, int error_code,
static const char SEP[] = ": "; static const char SEP[] = ": ";
static const char ERROR_STR[] = "error "; static const char ERROR_STR[] = "error ";
// Subtract 2 to account for terminating null characters in SEP and ERROR_STR. // Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
auto abs_value = static_cast<uint32_or_64_or_128_t<int>>(error_code); auto abs_value = static_cast<uint32_or_64_or_128_t<int>>(error_code);
if (internal::is_negative(error_code)) { if (internal::is_negative(error_code)) {
abs_value = 0 - abs_value; abs_value = 0 - abs_value;

View File

@ -337,12 +337,12 @@ inline typename Container::value_type* get_data(Container& c) {
#if defined(_SECURE_SCL) && _SECURE_SCL #if defined(_SECURE_SCL) && _SECURE_SCL
// Make a checked iterator to avoid MSVC warnings. // Make a checked iterator to avoid MSVC warnings.
template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>; template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>;
template <typename T> checked_ptr<T> make_checked(T* p, std::size_t size) { template <typename T> checked_ptr<T> make_checked(T* p, size_t size) {
return {p, size}; return {p, size};
} }
#else #else
template <typename T> using checked_ptr = T*; template <typename T> using checked_ptr = T*;
template <typename T> inline T* make_checked(T* p, std::size_t) { return p; } template <typename T> inline T* make_checked(T* p, size_t) { return p; }
#endif #endif
template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)> template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)>
@ -350,15 +350,14 @@ template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)>
__attribute__((no_sanitize("undefined"))) __attribute__((no_sanitize("undefined")))
#endif #endif
inline checked_ptr<typename Container::value_type> inline checked_ptr<typename Container::value_type>
reserve(std::back_insert_iterator<Container> it, std::size_t n) { reserve(std::back_insert_iterator<Container> it, size_t n) {
Container& c = get_container(it); Container& c = get_container(it);
std::size_t size = c.size(); size_t size = c.size();
c.resize(size + n); c.resize(size + n);
return make_checked(get_data(c) + size, n); return make_checked(get_data(c) + size, n);
} }
template <typename Iterator> template <typename Iterator> inline Iterator& reserve(Iterator& it, size_t) {
inline Iterator& reserve(Iterator& it, std::size_t) {
return it; return it;
} }
@ -378,7 +377,7 @@ inline Iterator base_iterator(Iterator, Iterator it) {
// discards them. // discards them.
class counting_iterator { class counting_iterator {
private: private:
std::size_t count_; size_t count_;
public: public:
using iterator_category = std::output_iterator_tag; using iterator_category = std::output_iterator_tag;
@ -393,7 +392,7 @@ class counting_iterator {
counting_iterator() : count_(0) {} counting_iterator() : count_(0) {}
std::size_t count() const { return count_; } size_t count() const { return count_; }
counting_iterator& operator++() { counting_iterator& operator++() {
++count_; ++count_;
@ -412,10 +411,10 @@ class counting_iterator {
template <typename OutputIt> class truncating_iterator_base { template <typename OutputIt> class truncating_iterator_base {
protected: protected:
OutputIt out_; OutputIt out_;
std::size_t limit_; size_t limit_;
std::size_t count_; size_t count_;
truncating_iterator_base(OutputIt out, std::size_t limit) truncating_iterator_base(OutputIt out, size_t limit)
: out_(out), limit_(limit), count_(0) {} : out_(out), limit_(limit), count_(0) {}
public: public:
@ -428,7 +427,7 @@ template <typename OutputIt> class truncating_iterator_base {
truncating_iterator_base; // Mark iterator as checked. truncating_iterator_base; // Mark iterator as checked.
OutputIt base() const { return out_; } OutputIt base() const { return out_; }
std::size_t count() const { return count_; } size_t count() const { return count_; }
}; };
// An output iterator that truncates the output and counts the number of objects // An output iterator that truncates the output and counts the number of objects
@ -446,7 +445,7 @@ class truncating_iterator<OutputIt, std::false_type>
public: public:
using value_type = typename truncating_iterator_base<OutputIt>::value_type; using value_type = typename truncating_iterator_base<OutputIt>::value_type;
truncating_iterator(OutputIt out, std::size_t limit) truncating_iterator(OutputIt out, size_t limit)
: truncating_iterator_base<OutputIt>(out, limit) {} : truncating_iterator_base<OutputIt>(out, limit) {}
truncating_iterator& operator++() { truncating_iterator& operator++() {
@ -469,7 +468,7 @@ template <typename OutputIt>
class truncating_iterator<OutputIt, std::true_type> class truncating_iterator<OutputIt, std::true_type>
: public truncating_iterator_base<OutputIt> { : public truncating_iterator_base<OutputIt> {
public: public:
truncating_iterator(OutputIt out, std::size_t limit) truncating_iterator(OutputIt out, size_t limit)
: truncating_iterator_base<OutputIt>(out, limit) {} : truncating_iterator_base<OutputIt>(out, limit) {}
template <typename T> truncating_iterator& operator=(T val) { template <typename T> truncating_iterator& operator=(T val) {
@ -568,7 +567,7 @@ template <typename T> constexpr bool use_grisu() {
template <typename T> template <typename T>
template <typename U> template <typename U>
void buffer<T>::append(const U* begin, const U* end) { void buffer<T>::append(const U* begin, const U* end) {
std::size_t new_size = size_ + to_unsigned(end - begin); size_t new_size = size_ + to_unsigned(end - begin);
reserve(new_size); reserve(new_size);
std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_); std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_);
size_ = new_size; size_ = new_size;
@ -619,7 +618,7 @@ enum { inline_buffer_size = 500 };
The output can be converted to an ``std::string`` with ``to_string(out)``. The output can be converted to an ``std::string`` with ``to_string(out)``.
\endrst \endrst
*/ */
template <typename T, std::size_t SIZE = inline_buffer_size, template <typename T, size_t SIZE = inline_buffer_size,
typename Allocator = std::allocator<T>> typename Allocator = std::allocator<T>>
class basic_memory_buffer : public internal::buffer<T> { class basic_memory_buffer : public internal::buffer<T> {
private: private:
@ -635,7 +634,7 @@ class basic_memory_buffer : public internal::buffer<T> {
} }
protected: protected:
void grow(std::size_t size) FMT_OVERRIDE; void grow(size_t size) FMT_OVERRIDE;
public: public:
using value_type = T; using value_type = T;
@ -652,7 +651,7 @@ class basic_memory_buffer : public internal::buffer<T> {
void move(basic_memory_buffer& other) { void move(basic_memory_buffer& other) {
alloc_ = std::move(other.alloc_); alloc_ = std::move(other.alloc_);
T* data = other.data(); T* data = other.data();
std::size_t size = other.size(), capacity = other.capacity(); size_t size = other.size(), capacity = other.capacity();
if (data == other.store_) { if (data == other.store_) {
this->set(store_, capacity); this->set(store_, capacity);
std::uninitialized_copy(other.store_, other.store_ + size, std::uninitialized_copy(other.store_, other.store_ + size,
@ -691,13 +690,13 @@ class basic_memory_buffer : public internal::buffer<T> {
Allocator get_allocator() const { return alloc_; } Allocator get_allocator() const { return alloc_; }
}; };
template <typename T, std::size_t SIZE, typename Allocator> template <typename T, size_t SIZE, typename Allocator>
void basic_memory_buffer<T, SIZE, Allocator>::grow(std::size_t size) { void basic_memory_buffer<T, SIZE, Allocator>::grow(size_t size) {
#ifdef FMT_FUZZ #ifdef FMT_FUZZ
if (size > 5000) throw std::runtime_error("fuzz mode - won't grow that much"); if (size > 5000) throw std::runtime_error("fuzz mode - won't grow that much");
#endif #endif
std::size_t old_capacity = this->capacity(); size_t old_capacity = this->capacity();
std::size_t new_capacity = old_capacity + old_capacity / 2; size_t new_capacity = old_capacity + old_capacity / 2;
if (size > new_capacity) new_capacity = size; if (size > new_capacity) new_capacity = size;
T* old_data = this->data(); T* old_data = this->data();
T* new_data = T* new_data =
@ -1397,8 +1396,8 @@ inline OutputIt write_padded(OutputIt out,
// Data for write_int that doesn't depend on output iterator type. It is used to // Data for write_int that doesn't depend on output iterator type. It is used to
// avoid template code bloat. // avoid template code bloat.
template <typename Char> struct write_int_data { template <typename Char> struct write_int_data {
std::size_t size; size_t size;
std::size_t padding; size_t padding;
write_int_data(int num_digits, string_view prefix, write_int_data(int num_digits, string_view prefix,
const basic_format_specs<Char>& specs) const basic_format_specs<Char>& specs)
@ -1685,7 +1684,7 @@ class arg_formatter_base {
// Attempts to reserve space for n extra characters in the output range. // Attempts to reserve space for n extra characters in the output range.
// Returns a pointer to the reserved range or a reference to out_. // Returns a pointer to the reserved range or a reference to out_.
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n)) { auto reserve(size_t n) -> decltype(internal::reserve(out_, n)) {
return internal::reserve(out_, n); return internal::reserve(out_, n);
} }
@ -1764,7 +1763,7 @@ class arg_formatter_base {
} }
template <typename Char> template <typename Char>
void write(const Char* s, std::size_t size, const format_specs& specs) { void write(const Char* s, size_t size, const format_specs& specs) {
auto width = specs.width != 0 auto width = specs.width != 0
? count_code_points(basic_string_view<Char>(s, size)) ? count_code_points(basic_string_view<Char>(s, size))
: 0; : 0;
@ -2868,7 +2867,7 @@ class format_int {
explicit format_int(unsigned long long value) : str_(format_decimal(value)) {} explicit format_int(unsigned long long value) : str_(format_decimal(value)) {}
/** Returns the number of characters written to the output buffer. */ /** Returns the number of characters written to the output buffer. */
std::size_t size() const { size_t size() const {
return internal::to_unsigned(buffer_ - str_ + buffer_size - 1); return internal::to_unsigned(buffer_ - str_ + buffer_size - 1);
} }
@ -3302,7 +3301,7 @@ template <typename T> inline std::wstring to_wstring(const T& value) {
return format(L"{}", value); return format(L"{}", value);
} }
template <typename Char, std::size_t SIZE> template <typename Char, size_t SIZE>
std::basic_string<Char> to_string(const basic_memory_buffer<Char, SIZE>& buf) { std::basic_string<Char> to_string(const basic_memory_buffer<Char, SIZE>& buf) {
return std::basic_string<Char>(buf.data(), buf.size()); return std::basic_string<Char>(buf.data(), buf.size());
} }
@ -3351,7 +3350,7 @@ inline typename buffer_context<Char>::iterator vformat_to(
return internal::vformat_to(buf, to_string_view(format_str), args); return internal::vformat_to(buf, to_string_view(format_str), args);
} }
template <typename S, typename... Args, std::size_t SIZE = inline_buffer_size, template <typename S, typename... Args, size_t SIZE = inline_buffer_size,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>> typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline typename buffer_context<Char>::iterator format_to( inline typename buffer_context<Char>::iterator format_to(
basic_memory_buffer<Char, SIZE>& buf, const S& format_str, Args&&... args) { basic_memory_buffer<Char, SIZE>& buf, const S& format_str, Args&&... args) {
@ -3406,7 +3405,7 @@ template <typename OutputIt> struct format_to_n_result {
/** Iterator past the end of the output range. */ /** Iterator past the end of the output range. */
OutputIt out; OutputIt out;
/** Total (not truncated) output size. */ /** Total (not truncated) output size. */
std::size_t size; size_t size;
}; };
template <typename OutputIt, typename Char = typename OutputIt::value_type> template <typename OutputIt, typename Char = typename OutputIt::value_type>
@ -3426,7 +3425,7 @@ make_format_to_n_args(const Args&... args) {
template <typename OutputIt, typename Char, typename... Args, template <typename OutputIt, typename Char, typename... Args,
FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)> FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)>
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, size_t n, basic_string_view<Char> format_str,
format_to_n_args<type_identity_t<OutputIt>, type_identity_t<Char>> args) { format_to_n_args<type_identity_t<OutputIt>, type_identity_t<Char>> args) {
auto it = vformat_to(internal::truncating_iterator<OutputIt>(out, n), auto it = vformat_to(internal::truncating_iterator<OutputIt>(out, n),
format_str, args); format_str, args);
@ -3443,7 +3442,7 @@ inline format_to_n_result<OutputIt> vformat_to_n(
template <typename OutputIt, typename S, typename... Args, template <typename OutputIt, typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value&& FMT_ENABLE_IF(internal::is_string<S>::value&&
internal::is_output_iterator<OutputIt>::value)> internal::is_output_iterator<OutputIt>::value)>
inline format_to_n_result<OutputIt> format_to_n(OutputIt out, std::size_t n, inline format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
const S& format_str, const S& format_str,
const Args&... args) { const Args&... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
@ -3466,7 +3465,7 @@ std::basic_string<Char> internal::vformat(
``format(format_str, args...)``. ``format(format_str, args...)``.
*/ */
template <typename... Args> template <typename... Args>
inline std::size_t formatted_size(string_view format_str, const Args&... args) { inline size_t formatted_size(string_view format_str, const Args&... args) {
return format_to(internal::counting_iterator(), format_str, args...).count(); return format_to(internal::counting_iterator(), format_str, args...).count();
} }
@ -3542,11 +3541,11 @@ FMT_CONSTEXPR internal::udl_formatter<Char, CHARS...> operator""_format() {
\endrst \endrst
*/ */
FMT_CONSTEXPR internal::udl_formatter<char> operator"" _format(const char* s, FMT_CONSTEXPR internal::udl_formatter<char> operator"" _format(const char* s,
std::size_t n) { size_t n) {
return {{s, n}}; return {{s, n}};
} }
FMT_CONSTEXPR internal::udl_formatter<wchar_t> operator"" _format( FMT_CONSTEXPR internal::udl_formatter<wchar_t> operator"" _format(
const wchar_t* s, std::size_t n) { const wchar_t* s, size_t n) {
return {{s, n}}; return {{s, n}};
} }
# endif // FMT_USE_UDL_TEMPLATE # endif // FMT_USE_UDL_TEMPLATE
@ -3561,12 +3560,11 @@ FMT_CONSTEXPR internal::udl_formatter<wchar_t> operator"" _format(
fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23);
\endrst \endrst
*/ */
FMT_CONSTEXPR internal::udl_arg<char> operator"" _a(const char* s, FMT_CONSTEXPR internal::udl_arg<char> operator"" _a(const char* s, size_t) {
std::size_t) {
return {s}; return {s};
} }
FMT_CONSTEXPR internal::udl_arg<wchar_t> operator"" _a(const wchar_t* s, FMT_CONSTEXPR internal::udl_arg<wchar_t> operator"" _a(const wchar_t* s,
std::size_t) { size_t) {
return {s}; return {s};
} }
} // namespace literals } // namespace literals

View File

@ -313,10 +313,10 @@ class file {
FMT_API long long size() const; FMT_API long long size() const;
// Attempts to read count bytes from the file into the specified buffer. // Attempts to read count bytes from the file into the specified buffer.
FMT_API std::size_t read(void* buffer, std::size_t count); FMT_API size_t read(void* buffer, size_t count);
// Attempts to write count bytes from the specified buffer to the file. // Attempts to write count bytes from the specified buffer to the file.
FMT_API std::size_t write(const void* buffer, std::size_t count); FMT_API size_t write(const void* buffer, size_t count);
// Duplicates a file descriptor with the dup function and returns // Duplicates a file descriptor with the dup function and returns
// the duplicate as a file object. // the duplicate as a file object.

View File

@ -1,2 +1,2 @@
#include "os.h" #include "os.h"
#warning "fmt/posix.h is deprecated; use fmt/os.h instead" #warning "fmt/posix.h is deprecated; use fmt/os.h instead"

View File

@ -508,7 +508,8 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
auto str_end = str + specs.precision; auto str_end = str + specs.precision;
auto nul = std::find(str, str_end, Char()); auto nul = std::find(str, str_end, Char());
arg = internal::make_arg<basic_printf_context>(basic_string_view<Char>( arg = internal::make_arg<basic_printf_context>(basic_string_view<Char>(
str, internal::to_unsigned(nul != str_end ? nul - str : specs.precision))); str,
internal::to_unsigned(nul != str_end ? nul - str : specs.precision)));
} }
if (specs.alt && visit_format_arg(internal::is_zero_int(), arg)) if (specs.alt && visit_format_arg(internal::is_zero_int(), arg))
specs.alt = false; specs.alt = false;
@ -546,7 +547,7 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
convert_arg<intmax_t>(arg, t); convert_arg<intmax_t>(arg, t);
break; break;
case 'z': case 'z':
convert_arg<std::size_t>(arg, t); convert_arg<size_t>(arg, t);
break; break;
case 't': case 't':
convert_arg<std::ptrdiff_t>(arg, t); convert_arg<std::ptrdiff_t>(arg, t);
@ -651,7 +652,7 @@ inline int vfprintf(
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args) { basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
vprintf(buffer, to_string_view(format), args); vprintf(buffer, to_string_view(format), args);
std::size_t size = buffer.size(); size_t size = buffer.size();
return std::fwrite(buffer.data(), sizeof(Char), size, f) < size return std::fwrite(buffer.data(), sizeof(Char), size, f) < size
? -1 ? -1
: static_cast<int>(size); : static_cast<int>(size);

View File

@ -33,7 +33,7 @@ template <typename Char> struct formatting_base {
template <typename Char, typename Enable = void> template <typename Char, typename Enable = void>
struct formatting_range : formatting_base<Char> { struct formatting_range : formatting_base<Char> {
static FMT_CONSTEXPR_DECL const std::size_t range_length_limit = static FMT_CONSTEXPR_DECL const size_t range_length_limit =
FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the
// range. // range.
Char prefix; Char prefix;
@ -118,26 +118,24 @@ template <typename T> class is_tuple_like_ {
#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1900 #if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1900
template <typename T, T... N> template <typename T, T... N>
using integer_sequence = std::integer_sequence<T, N...>; using integer_sequence = std::integer_sequence<T, N...>;
template <std::size_t... N> using index_sequence = std::index_sequence<N...>; template <size_t... N> using index_sequence = std::index_sequence<N...>;
template <std::size_t N> template <size_t N> using make_index_sequence = std::make_index_sequence<N>;
using make_index_sequence = std::make_index_sequence<N>;
#else #else
template <typename T, T... N> struct integer_sequence { template <typename T, T... N> struct integer_sequence {
using value_type = T; using value_type = T;
static FMT_CONSTEXPR std::size_t size() { return sizeof...(N); } static FMT_CONSTEXPR size_t size() { return sizeof...(N); }
}; };
template <std::size_t... N> template <size_t... N> using index_sequence = integer_sequence<size_t, N...>;
using index_sequence = integer_sequence<std::size_t, N...>;
template <typename T, std::size_t N, T... Ns> template <typename T, size_t N, T... Ns>
struct make_integer_sequence : make_integer_sequence<T, N - 1, N - 1, Ns...> {}; struct make_integer_sequence : make_integer_sequence<T, N - 1, N - 1, Ns...> {};
template <typename T, T... Ns> template <typename T, T... Ns>
struct make_integer_sequence<T, 0, Ns...> : integer_sequence<T, Ns...> {}; struct make_integer_sequence<T, 0, Ns...> : integer_sequence<T, Ns...> {};
template <std::size_t N> template <size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>; using make_index_sequence = make_integer_sequence<size_t, N>;
#endif #endif
template <class Tuple, class F, size_t... Is> template <class Tuple, class F, size_t... Is>
@ -212,7 +210,7 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
} }
formatting_tuple<Char>& formatting; formatting_tuple<Char>& formatting;
std::size_t& i; size_t& i;
typename std::add_lvalue_reference<decltype( typename std::add_lvalue_reference<decltype(
std::declval<FormatContext>().out())>::type out; std::declval<FormatContext>().out())>::type out;
}; };
@ -228,7 +226,7 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
template <typename FormatContext = format_context> template <typename FormatContext = format_context>
auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) { auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) {
auto out = ctx.out(); auto out = ctx.out();
std::size_t i = 0; size_t i = 0;
internal::copy(formatting.prefix, out); internal::copy(formatting.prefix, out);
internal::for_each(values, format_each<FormatContext>{formatting, i, out}); internal::for_each(values, format_each<FormatContext>{formatting, i, out});
@ -263,7 +261,7 @@ struct formatter<RangeT, Char,
typename FormatContext::iterator format(const RangeT& values, typename FormatContext::iterator format(const RangeT& values,
FormatContext& ctx) { FormatContext& ctx) {
auto out = internal::copy(formatting.prefix, ctx.out()); auto out = internal::copy(formatting.prefix, ctx.out());
std::size_t i = 0; size_t i = 0;
for (auto it = values.begin(), end = values.end(); it != end; ++it) { for (auto it = values.begin(), end = values.end(); it != end; ++it) {
if (i > 0) { if (i > 0) {
if (formatting.add_prepostfix_space) *out++ = ' '; if (formatting.add_prepostfix_space) *out++ = ' ';

View File

@ -10,10 +10,11 @@
#endif #endif
#include "fmt/chrono.h" #include "fmt/chrono.h"
#include "gtest-extra.h"
#include <iomanip> #include <iomanip>
#include "gtest-extra.h"
std::tm make_tm() { std::tm make_tm() {
auto time = std::tm(); auto time = std::tm();
time.tm_mday = 1; time.tm_mday = 1;

View File

@ -6,6 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#include "fmt/color.h" #include "fmt/color.h"
#include "gtest-extra.h" #include "gtest-extra.h"
TEST(ColorsTest, ColorsPrint) { TEST(ColorsTest, ColorsPrint) {

View File

@ -6,6 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#include <stdint.h> #include <stdint.h>
#include <cctype> #include <cctype>
#include <cfloat> #include <cfloat>
#include <climits> #include <climits>

View File

@ -83,20 +83,20 @@ TEST(BufferTest, Nonmoveable) {
// A test buffer with a dummy grow method. // A test buffer with a dummy grow method.
template <typename T> struct test_buffer : buffer<T> { template <typename T> struct test_buffer : buffer<T> {
void grow(std::size_t capacity) { this->set(nullptr, capacity); } void grow(size_t capacity) { this->set(nullptr, capacity); }
}; };
template <typename T> struct mock_buffer : buffer<T> { template <typename T> struct mock_buffer : buffer<T> {
MOCK_METHOD1(do_grow, void(std::size_t capacity)); MOCK_METHOD1(do_grow, void(size_t capacity));
void grow(std::size_t capacity) { void grow(size_t capacity) {
this->set(this->data(), capacity); this->set(this->data(), capacity);
do_grow(capacity); do_grow(capacity);
} }
mock_buffer() {} mock_buffer() {}
mock_buffer(T* data) { this->set(data, 0); } mock_buffer(T* data) { this->set(data, 0); }
mock_buffer(T* data, std::size_t capacity) { this->set(data, capacity); } mock_buffer(T* data, size_t capacity) { this->set(data, capacity); }
}; };
TEST(BufferTest, Ctor) { TEST(BufferTest, Ctor) {
@ -115,7 +115,7 @@ TEST(BufferTest, Ctor) {
} }
{ {
int dummy; int dummy;
std::size_t capacity = std::numeric_limits<std::size_t>::max(); size_t capacity = std::numeric_limits<size_t>::max();
mock_buffer<int> buffer(&dummy, capacity); mock_buffer<int> buffer(&dummy, capacity);
EXPECT_EQ(&dummy, &buffer[0]); EXPECT_EQ(&dummy, &buffer[0]);
EXPECT_EQ(static_cast<size_t>(0), buffer.size()); EXPECT_EQ(static_cast<size_t>(0), buffer.size());
@ -375,7 +375,7 @@ struct check_custom {
struct test_buffer : fmt::internal::buffer<char> { struct test_buffer : fmt::internal::buffer<char> {
char data[10]; char data[10];
test_buffer() : fmt::internal::buffer<char>(data, 0, 10) {} test_buffer() : fmt::internal::buffer<char>(data, 0, 10) {}
void grow(std::size_t) {} void grow(size_t) {}
} buffer; } buffer;
fmt::internal::buffer<char>& base = buffer; fmt::internal::buffer<char>& base = buffer;
fmt::format_parse_context parse_ctx(""); fmt::format_parse_context parse_ctx("");
@ -496,9 +496,9 @@ TEST(StringViewTest, Length) {
// Check string_view's comparison operator. // Check string_view's comparison operator.
template <template <typename> class Op> void check_op() { template <template <typename> class Op> void check_op() {
const char* inputs[] = {"foo", "fop", "fo"}; const char* inputs[] = {"foo", "fop", "fo"};
std::size_t num_inputs = sizeof(inputs) / sizeof(*inputs); size_t num_inputs = sizeof(inputs) / sizeof(*inputs);
for (std::size_t i = 0; i < num_inputs; ++i) { for (size_t i = 0; i < num_inputs; ++i) {
for (std::size_t j = 0; j < num_inputs; ++j) { for (size_t j = 0; j < num_inputs; ++j) {
string_view lhs(inputs[i]), rhs(inputs[j]); string_view lhs(inputs[i]), rhs(inputs[j]);
EXPECT_EQ(Op<int>()(lhs.compare(rhs), 0), Op<string_view>()(lhs, rhs)); EXPECT_EQ(Op<int>()(lhs.compare(rhs), 0), Op<string_view>()(lhs, rhs));
} }
@ -584,7 +584,7 @@ template <typename Char> class my_string {
public: public:
my_string(const Char* s) : s_(s) {} my_string(const Char* s) : s_(s) {}
const Char* data() const FMT_NOEXCEPT { return s_.data(); } const Char* data() const FMT_NOEXCEPT { return s_.data(); }
std::size_t length() const FMT_NOEXCEPT { return s_.size(); } size_t length() const FMT_NOEXCEPT { return s_.size(); }
operator const Char*() const { return s_.c_str(); } operator const Char*() const { return s_.c_str(); }
private: private:

View File

@ -376,7 +376,7 @@ TEST(FormatTest, StrError) {
int result = int result =
fmt::internal::safe_strerror(error_code, message = buffer, BUFFER_SIZE); fmt::internal::safe_strerror(error_code, message = buffer, BUFFER_SIZE);
EXPECT_EQ(result, 0); EXPECT_EQ(result, 0);
std::size_t message_size = std::strlen(message); size_t message_size = std::strlen(message);
EXPECT_GE(BUFFER_SIZE - 1u, message_size); EXPECT_GE(BUFFER_SIZE - 1u, message_size);
EXPECT_EQ(get_system_error(error_code), message); EXPECT_EQ(get_system_error(error_code), message);
@ -408,14 +408,14 @@ TEST(FormatTest, FormatErrorCode) {
EXPECT_EQ(msg, to_string(buffer)); EXPECT_EQ(msg, to_string(buffer));
} }
int codes[] = {42, -1}; int codes[] = {42, -1};
for (std::size_t i = 0, n = sizeof(codes) / sizeof(*codes); i < n; ++i) { for (size_t i = 0, n = sizeof(codes) / sizeof(*codes); i < n; ++i) {
// Test maximum buffer size. // Test maximum buffer size.
msg = fmt::format("error {}", codes[i]); msg = fmt::format("error {}", codes[i]);
fmt::memory_buffer buffer; fmt::memory_buffer buffer;
std::string prefix(fmt::inline_buffer_size - msg.size() - sep.size(), 'x'); std::string prefix(fmt::inline_buffer_size - msg.size() - sep.size(), 'x');
fmt::internal::format_error_code(buffer, codes[i], prefix); fmt::internal::format_error_code(buffer, codes[i], prefix);
EXPECT_EQ(prefix + sep + msg, to_string(buffer)); EXPECT_EQ(prefix + sep + msg, to_string(buffer));
std::size_t size = fmt::inline_buffer_size; size_t size = fmt::inline_buffer_size;
EXPECT_EQ(size, buffer.size()); EXPECT_EQ(size, buffer.size());
buffer.resize(0); buffer.resize(0);
// Test with a message that doesn't fit into the buffer. // Test with a message that doesn't fit into the buffer.

View File

@ -36,8 +36,6 @@
#undef ERROR #undef ERROR
using std::size_t;
using fmt::basic_memory_buffer; using fmt::basic_memory_buffer;
using fmt::format; using fmt::format;
using fmt::format_error; using fmt::format_error;
@ -299,7 +297,7 @@ TEST(MemoryBufferTest, Grow) {
mock_allocator<int> alloc; mock_allocator<int> alloc;
struct TestMemoryBuffer : Base { struct TestMemoryBuffer : Base {
TestMemoryBuffer(Allocator alloc) : Base(alloc) {} TestMemoryBuffer(Allocator alloc) : Base(alloc) {}
void grow(std::size_t size) { Base::grow(size); } void grow(size_t size) { Base::grow(size); }
} buffer((Allocator(&alloc))); } buffer((Allocator(&alloc)));
buffer.resize(7); buffer.resize(7);
using fmt::internal::to_unsigned; using fmt::internal::to_unsigned;
@ -327,7 +325,7 @@ TEST(MemoryBufferTest, Allocator) {
basic_memory_buffer<char, 10, TestAllocator> buffer2( basic_memory_buffer<char, 10, TestAllocator> buffer2(
(TestAllocator(&alloc))); (TestAllocator(&alloc)));
EXPECT_EQ(&alloc, buffer2.get_allocator().get()); EXPECT_EQ(&alloc, buffer2.get_allocator().get());
std::size_t size = 2 * fmt::inline_buffer_size; size_t size = 2 * fmt::inline_buffer_size;
EXPECT_CALL(alloc, allocate(size)).WillOnce(Return(&mem)); EXPECT_CALL(alloc, allocate(size)).WillOnce(Return(&mem));
buffer2.reserve(size); buffer2.reserve(size);
EXPECT_CALL(alloc, deallocate(&mem, size)); EXPECT_CALL(alloc, deallocate(&mem, size));
@ -338,7 +336,7 @@ TEST(MemoryBufferTest, ExceptionInDeallocate) {
typedef allocator_ref<mock_allocator<char>> TestAllocator; typedef allocator_ref<mock_allocator<char>> TestAllocator;
StrictMock<mock_allocator<char>> alloc; StrictMock<mock_allocator<char>> alloc;
basic_memory_buffer<char, 10, TestAllocator> buffer((TestAllocator(&alloc))); basic_memory_buffer<char, 10, TestAllocator> buffer((TestAllocator(&alloc)));
std::size_t size = 2 * fmt::inline_buffer_size; size_t size = 2 * fmt::inline_buffer_size;
std::vector<char> mem(size); std::vector<char> mem(size);
{ {
EXPECT_CALL(alloc, allocate(size)).WillOnce(Return(&mem[0])); EXPECT_CALL(alloc, allocate(size)).WillOnce(Return(&mem[0]));
@ -353,7 +351,7 @@ TEST(MemoryBufferTest, ExceptionInDeallocate) {
EXPECT_THROW(buffer.reserve(2 * size), std::exception); EXPECT_THROW(buffer.reserve(2 * size), std::exception);
EXPECT_EQ(&mem2[0], &buffer[0]); EXPECT_EQ(&mem2[0], &buffer[0]);
// Check that the data has been copied. // Check that the data has been copied.
for (std::size_t i = 0; i < size; ++i) EXPECT_EQ('x', buffer[i]); for (size_t i = 0; i < size; ++i) EXPECT_EQ('x', buffer[i]);
} }
EXPECT_CALL(alloc, deallocate(&mem2[0], 2 * size)); EXPECT_CALL(alloc, deallocate(&mem2[0], 2 * size));
} }
@ -608,9 +606,7 @@ TEST(FormatterTest, RightAlign) {
} }
#if FMT_NUMERIC_ALIGN #if FMT_NUMERIC_ALIGN
TEST(FormatterTest, NumericAlign) { TEST(FormatterTest, NumericAlign) { EXPECT_EQ("0042", format("{0:=4}", 42)); }
EXPECT_EQ("0042", format("{0:=4}", 42));
}
#endif #endif
TEST(FormatterTest, CenterAlign) { TEST(FormatterTest, CenterAlign) {
@ -801,7 +797,7 @@ TEST(FormatterTest, Width) {
safe_sprintf(format_str, "{0:%u", UINT_MAX); safe_sprintf(format_str, "{0:%u", UINT_MAX);
increment(format_str + 3); increment(format_str + 3);
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
std::size_t size = std::strlen(format_str); size_t size = std::strlen(format_str);
format_str[size] = '}'; format_str[size] = '}';
format_str[size + 1] = 0; format_str[size + 1] = 0;
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
@ -831,7 +827,7 @@ TEST(FormatterTest, RuntimeWidth) {
safe_sprintf(format_str, "{0:{%u", UINT_MAX); safe_sprintf(format_str, "{0:{%u", UINT_MAX);
increment(format_str + 4); increment(format_str + 4);
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
std::size_t size = std::strlen(format_str); size_t size = std::strlen(format_str);
format_str[size] = '}'; format_str[size] = '}';
format_str[size + 1] = 0; format_str[size + 1] = 0;
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
@ -884,7 +880,7 @@ TEST(FormatterTest, Precision) {
safe_sprintf(format_str, "{0:.%u", UINT_MAX); safe_sprintf(format_str, "{0:.%u", UINT_MAX);
increment(format_str + 4); increment(format_str + 4);
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
std::size_t size = std::strlen(format_str); size_t size = std::strlen(format_str);
format_str[size] = '}'; format_str[size] = '}';
format_str[size + 1] = 0; format_str[size + 1] = 0;
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
@ -976,7 +972,7 @@ TEST(FormatterTest, RuntimePrecision) {
safe_sprintf(format_str, "{0:.{%u", UINT_MAX); safe_sprintf(format_str, "{0:.{%u", UINT_MAX);
increment(format_str + 5); increment(format_str + 5);
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
std::size_t size = std::strlen(format_str); size_t size = std::strlen(format_str);
format_str[size] = '}'; format_str[size] = '}';
format_str[size + 1] = 0; format_str[size + 1] = 0;
EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big"); EXPECT_THROW_MSG(format(format_str, 0), format_error, "number is too big");
@ -1463,7 +1459,7 @@ class QString {
}; };
fmt::basic_string_view<wchar_t> to_string_view(const QString& s) FMT_NOEXCEPT { fmt::basic_string_view<wchar_t> to_string_view(const QString& s) FMT_NOEXCEPT {
return {s.utf16(), static_cast<std::size_t>(s.size())}; return {s.utf16(), static_cast<size_t>(s.size())};
} }
} // namespace fake_qt } // namespace fake_qt

View File

@ -25,7 +25,7 @@ void invoke_inner(fmt::string_view formatstring, const Item item) {
// Item is the underlying type for duration (int, long etc) // Item is the underlying type for duration (int, long etc)
template <typename Item> template <typename Item>
void invoke_outer(const uint8_t* Data, std::size_t Size, const int scaling) { void invoke_outer(const uint8_t* Data, size_t Size, const int scaling) {
// always use a fixed location of the data // always use a fixed location of the data
using fmt_fuzzer::Nfixed; using fmt_fuzzer::Nfixed;
@ -97,7 +97,7 @@ void invoke_outer(const uint8_t* Data, std::size_t Size, const int scaling) {
// doit_impl<Item,std::yotta>(buf.data(),item); // doit_impl<Item,std::yotta>(buf.data(),item);
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
if (Size <= 4) { if (Size <= 4) {
return 0; return 0;
} }

View File

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include "fuzzer_common.h" #include "fuzzer_common.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size); extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
std::ifstream in(argv[i]); std::ifstream in(argv[i]);
@ -13,7 +13,7 @@ int main(int argc, char* argv[]) {
const auto pos = in.tellg(); const auto pos = in.tellg();
assert(pos >= 0); assert(pos >= 0);
in.seekg(0, std::ios_base::beg); in.seekg(0, std::ios_base::beg);
std::vector<char> buf(static_cast<std::size_t>(pos)); std::vector<char> buf(static_cast<size_t>(pos));
in.read(buf.data(), static_cast<long>(buf.size())); in.read(buf.data(), static_cast<long>(buf.size()));
assert(in.gcount() == pos); assert(in.gcount() == pos);
LLVMFuzzerTestOneInput(fmt_fuzzer::as_bytes(buf.data()), buf.size()); LLVMFuzzerTestOneInput(fmt_fuzzer::as_bytes(buf.data()), buf.size());

View File

@ -10,7 +10,7 @@
#include "fuzzer_common.h" #include "fuzzer_common.h"
template <typename Item1> template <typename Item1>
void invoke_fmt(const uint8_t* Data, std::size_t Size, unsigned int argsize) { void invoke_fmt(const uint8_t* Data, size_t Size, unsigned int argsize) {
constexpr auto N1 = sizeof(Item1); constexpr auto N1 = sizeof(Item1);
static_assert(N1 <= fmt_fuzzer::Nfixed, "Nfixed too small"); static_assert(N1 <= fmt_fuzzer::Nfixed, "Nfixed too small");
if (Size <= fmt_fuzzer::Nfixed) { if (Size <= fmt_fuzzer::Nfixed) {
@ -105,7 +105,7 @@ template <typename Callback> void invoke(int index, Callback callback) {
} }
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
if (Size <= 3) { if (Size <= 3) {
return 0; return 0;
} }

View File

@ -13,7 +13,7 @@
using fmt_fuzzer::Nfixed; using fmt_fuzzer::Nfixed;
template <typename Item> template <typename Item>
void invoke_fmt(const uint8_t* Data, std::size_t Size) { void invoke_fmt(const uint8_t* Data, size_t Size) {
constexpr auto N = sizeof(Item); constexpr auto N = sizeof(Item);
static_assert(N <= Nfixed, "Nfixed is too small"); static_assert(N <= Nfixed, "Nfixed is too small");
if (Size <= Nfixed) { if (Size <= Nfixed) {
@ -40,7 +40,7 @@ void invoke_fmt(const uint8_t* Data, std::size_t Size) {
#endif #endif
} }
void invoke_fmt_time(const uint8_t* Data, std::size_t Size) { void invoke_fmt_time(const uint8_t* Data, size_t Size) {
using Item = std::time_t; using Item = std::time_t;
constexpr auto N = sizeof(Item); constexpr auto N = sizeof(Item);
static_assert(N <= Nfixed, "Nfixed too small"); static_assert(N <= Nfixed, "Nfixed too small");
@ -69,7 +69,7 @@ void invoke_fmt_time(const uint8_t* Data, std::size_t Size) {
} }
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
if (Size <= 3) { if (Size <= 3) {
return 0; return 0;
} }

View File

@ -10,7 +10,7 @@
using fmt_fuzzer::Nfixed; using fmt_fuzzer::Nfixed;
template <typename Item1, typename Item2> template <typename Item1, typename Item2>
void invoke_fmt(const uint8_t* Data, std::size_t Size) { void invoke_fmt(const uint8_t* Data, size_t Size) {
constexpr auto N1 = sizeof(Item1); constexpr auto N1 = sizeof(Item1);
constexpr auto N2 = sizeof(Item2); constexpr auto N2 = sizeof(Item2);
static_assert(N1 <= Nfixed, "size1 exceeded"); static_assert(N1 <= Nfixed, "size1 exceeded");
@ -90,7 +90,7 @@ template <typename Callback> void invoke(int index, Callback callback) {
} }
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
if (Size <= 3) { if (Size <= 3) {
return 0; return 0;
} }

View File

@ -10,7 +10,7 @@
constexpr auto Nfixed = fmt_fuzzer::Nfixed; constexpr auto Nfixed = fmt_fuzzer::Nfixed;
template <typename Item1, typename Item2> template <typename Item1, typename Item2>
void invoke_fmt(const uint8_t* Data, std::size_t Size) { void invoke_fmt(const uint8_t* Data, size_t Size) {
constexpr auto N1 = sizeof(Item1); constexpr auto N1 = sizeof(Item1);
constexpr auto N2 = sizeof(Item2); constexpr auto N2 = sizeof(Item2);
static_assert(N1 <= Nfixed, "size1 exceeded"); static_assert(N1 <= Nfixed, "size1 exceeded");
@ -86,7 +86,7 @@ template <typename Callback> void invoke(int index, Callback callback) {
} }
} }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
if (Size <= 3) { if (Size <= 3) {
return 0; return 0;
} }

View File

@ -344,6 +344,7 @@ class GTEST_API_ SingleFailureChecker {
# include <sys/mman.h> // NOLINT # include <sys/mman.h> // NOLINT
# include <sys/time.h> // NOLINT # include <sys/time.h> // NOLINT
# include <unistd.h> // NOLINT # include <unistd.h> // NOLINT
# include <string> # include <string>
#elif GTEST_OS_SYMBIAN #elif GTEST_OS_SYMBIAN
@ -7728,6 +7729,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
# include <sys/syslimits.h> # include <sys/syslimits.h>
#else #else
# include <limits.h> # include <limits.h>
# include <climits> // Some Linux distributions define PATH_MAX here. # include <climits> // Some Linux distributions define PATH_MAX here.
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
@ -8899,6 +8901,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_value) {
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <string> #include <string>
@ -9494,6 +9497,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
// This file implements cardinalities. // This file implements cardinalities.
#include <limits.h> #include <limits.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -9646,6 +9650,7 @@ GTEST_API_ Cardinality Exactly(int n) { return Between(n, n); }
// USE THEM IN USER CODE. // USE THEM IN USER CODE.
#include <ctype.h> #include <ctype.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <string> #include <string>
@ -9808,6 +9813,7 @@ GTEST_API_ void Log(LogSeverity severity, const string& message,
// utilities for defining matchers. // utilities for defining matchers.
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -10291,6 +10297,7 @@ bool UnorderedElementsAreMatcherImplBase::
// EXPECT_CALL). // EXPECT_CALL).
#include <stdlib.h> #include <stdlib.h>
#include <iostream> // NOLINT #include <iostream> // NOLINT
#include <map> #include <map>
#include <set> #include <set>

View File

@ -8,6 +8,7 @@
#include "gtest-extra.h" #include "gtest-extra.h"
#include <gtest/gtest-spi.h> #include <gtest/gtest-spi.h>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
@ -167,22 +168,24 @@ TEST_F(SingleEvaluationTest, FailedEXPECT_WRITE) {
// Tests that assertion arguments are evaluated exactly once. // Tests that assertion arguments are evaluated exactly once.
TEST_F(SingleEvaluationTest, WriteTests) { TEST_F(SingleEvaluationTest, WriteTests) {
// successful EXPECT_WRITE // successful EXPECT_WRITE
EXPECT_WRITE(stdout, EXPECT_WRITE(
{ // NOLINT stdout,
a_++; { // NOLINT
std::printf("test"); a_++;
}, std::printf("test");
(b_++, "test")); },
(b_++, "test"));
EXPECT_EQ(1, a_); EXPECT_EQ(1, a_);
EXPECT_EQ(1, b_); EXPECT_EQ(1, b_);
// failed EXPECT_WRITE // failed EXPECT_WRITE
EXPECT_NONFATAL_FAILURE(EXPECT_WRITE(stdout, EXPECT_NONFATAL_FAILURE(EXPECT_WRITE(
{ // NOLINT stdout,
a_++; { // NOLINT
std::printf("test"); a_++;
}, std::printf("test");
(b_++, "other")), },
(b_++, "other")),
"Actual: test"); "Actual: test");
EXPECT_EQ(2, a_); EXPECT_EQ(2, a_);
EXPECT_EQ(2, b_); EXPECT_EQ(2, b_);
@ -417,16 +420,17 @@ TEST(OutputRedirectTest, ErrorInDtor) {
std::unique_ptr<OutputRedirect> redir(new OutputRedirect(f.get())); std::unique_ptr<OutputRedirect> redir(new OutputRedirect(f.get()));
// Put a character in a file buffer. // Put a character in a file buffer.
EXPECT_EQ('x', fputc('x', f.get())); EXPECT_EQ('x', fputc('x', f.get()));
EXPECT_WRITE(stderr, EXPECT_WRITE(
{ stderr,
// The close function must be called inside EXPECT_WRITE, {
// otherwise the system may recycle closed file descriptor when // The close function must be called inside EXPECT_WRITE,
// redirecting the output in EXPECT_STDERR and the second close // otherwise the system may recycle closed file descriptor when
// will break output redirection. // redirecting the output in EXPECT_STDERR and the second close
FMT_POSIX(close(write_fd)); // will break output redirection.
SUPPRESS_ASSERT(redir.reset(nullptr)); FMT_POSIX(close(write_fd));
}, SUPPRESS_ASSERT(redir.reset(nullptr));
format_system_error(EBADF, "cannot flush stream")); },
format_system_error(EBADF, "cannot flush stream"));
write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail
} }

View File

@ -57,7 +57,7 @@ std::string OutputRedirect::restore_and_read() {
if (read_end_.descriptor() == -1) return content; // Already read. if (read_end_.descriptor() == -1) return content; // Already read.
enum { BUFFER_SIZE = 4096 }; enum { BUFFER_SIZE = 4096 };
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
std::size_t count = 0; size_t count = 0;
do { do {
count = read_end_.read(buffer, BUFFER_SIZE); count = read_end_.read(buffer, BUFFER_SIZE);
content.append(buffer, count); content.append(buffer, count);
@ -66,9 +66,9 @@ std::string OutputRedirect::restore_and_read() {
return content; return content;
} }
std::string read(file& f, std::size_t count) { std::string read(file& f, size_t count) {
std::string buffer(count, '\0'); std::string buffer(count, '\0');
std::size_t n = 0, offset = 0; size_t n = 0, offset = 0;
do { do {
n = f.read(&buffer[offset], count - offset); n = f.read(&buffer[offset], count - offset);
// We can't read more than size_t bytes since count has type size_t. // We can't read more than size_t bytes since count has type size_t.

View File

@ -9,8 +9,9 @@
#define FMT_GTEST_EXTRA_H_ #define FMT_GTEST_EXTRA_H_
#include <string> #include <string>
#include "gmock.h"
#include "fmt/os.h" #include "fmt/os.h"
#include "gmock.h"
#define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \ #define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
@ -137,7 +138,7 @@ class SuppressAssert {
EXPECT_SYSTEM_ERROR(SUPPRESS_ASSERT(statement), error_code, message) EXPECT_SYSTEM_ERROR(SUPPRESS_ASSERT(statement), error_code, message)
// Attempts to read count characters from a file. // Attempts to read count characters from a file.
std::string read(fmt::file& f, std::size_t count); std::string read(fmt::file& f, size_t count);
# define EXPECT_READ(file, expected_content) \ # define EXPECT_READ(file, expected_content) \
EXPECT_EQ(expected_content, read(file, std::strlen(expected_content))) EXPECT_EQ(expected_content, read(file, std::strlen(expected_content)))

View File

@ -6,6 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#include "fmt/locale.h" #include "fmt/locale.h"
#include "gmock.h" #include "gmock.h"
using fmt::internal::max_value; using fmt::internal::max_value;

View File

@ -16,8 +16,8 @@ template <typename T> class mock_allocator {
mock_allocator() {} mock_allocator() {}
mock_allocator(const mock_allocator&) {} mock_allocator(const mock_allocator&) {}
typedef T value_type; typedef T value_type;
MOCK_METHOD1_T(allocate, T*(std::size_t n)); MOCK_METHOD1_T(allocate, T*(size_t n));
MOCK_METHOD2_T(deallocate, void(T* p, std::size_t n)); MOCK_METHOD2_T(deallocate, void(T* p, size_t n));
}; };
template <typename Allocator> class allocator_ref { template <typename Allocator> class allocator_ref {
@ -51,10 +51,10 @@ template <typename Allocator> class allocator_ref {
public: public:
Allocator* get() const { return alloc_; } Allocator* get() const { return alloc_; }
value_type* allocate(std::size_t n) { value_type* allocate(size_t n) {
return std::allocator_traits<Allocator>::allocate(*alloc_, n); return std::allocator_traits<Allocator>::allocate(*alloc_, n);
} }
void deallocate(value_type* p, std::size_t n) { alloc_->deallocate(p, n); } void deallocate(value_type* p, size_t n) { alloc_->deallocate(p, n); }
}; };
#endif // FMT_MOCK_ALLOCATOR_H_ #endif // FMT_MOCK_ALLOCATOR_H_

View File

@ -5,11 +5,12 @@
// //
// For the license information refer to format.h. // For the license information refer to format.h.
#include "fmt/os.h"
#include <cstdlib> // std::exit #include <cstdlib> // std::exit
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include "fmt/os.h"
#include "gtest-extra.h" #include "gtest-extra.h"
#include "util.h" #include "util.h"
@ -164,10 +165,10 @@ static file open_file() {
// Attempts to write a string to a file. // Attempts to write a string to a file.
static void write(file& f, fmt::string_view s) { static void write(file& f, fmt::string_view s) {
std::size_t num_chars_left = s.size(); size_t num_chars_left = s.size();
const char* ptr = s.data(); const char* ptr = s.data();
do { do {
std::size_t count = f.write(ptr, num_chars_left); size_t count = f.write(ptr, num_chars_left);
ptr += count; ptr += count;
// We can't write more than size_t bytes since num_chars_left // We can't write more than size_t bytes since num_chars_left
// has type size_t. // has type size_t.
@ -238,16 +239,17 @@ TEST(BufferedFileTest, CloseFileInDtor) {
TEST(BufferedFileTest, CloseErrorInDtor) { TEST(BufferedFileTest, CloseErrorInDtor) {
std::unique_ptr<buffered_file> f(new buffered_file(open_buffered_file())); std::unique_ptr<buffered_file> f(new buffered_file(open_buffered_file()));
EXPECT_WRITE(stderr, EXPECT_WRITE(
{ stderr,
// The close function must be called inside EXPECT_WRITE, {
// otherwise the system may recycle closed file descriptor when // The close function must be called inside EXPECT_WRITE,
// redirecting the output in EXPECT_STDERR and the second close // otherwise the system may recycle closed file descriptor when
// will break output redirection. // redirecting the output in EXPECT_STDERR and the second close
FMT_POSIX(close(f->fileno())); // will break output redirection.
SUPPRESS_ASSERT(f.reset(nullptr)); FMT_POSIX(close(f->fileno()));
}, SUPPRESS_ASSERT(f.reset(nullptr));
format_system_error(EBADF, "cannot close file") + "\n"); },
format_system_error(EBADF, "cannot close file") + "\n");
} }
TEST(BufferedFileTest, Close) { TEST(BufferedFileTest, Close) {
@ -369,16 +371,17 @@ TEST(FileTest, CloseFileInDtor) {
TEST(FileTest, CloseErrorInDtor) { TEST(FileTest, CloseErrorInDtor) {
std::unique_ptr<file> f(new file(open_file())); std::unique_ptr<file> f(new file(open_file()));
EXPECT_WRITE(stderr, EXPECT_WRITE(
{ stderr,
// The close function must be called inside EXPECT_WRITE, {
// otherwise the system may recycle closed file descriptor when // The close function must be called inside EXPECT_WRITE,
// redirecting the output in EXPECT_STDERR and the second close // otherwise the system may recycle closed file descriptor when
// will break output redirection. // redirecting the output in EXPECT_STDERR and the second close
FMT_POSIX(close(f->descriptor())); // will break output redirection.
SUPPRESS_ASSERT(f.reset(nullptr)); FMT_POSIX(close(f->descriptor()));
}, SUPPRESS_ASSERT(f.reset(nullptr));
format_system_error(EBADF, "cannot close file") + "\n"); },
format_system_error(EBADF, "cannot close file") + "\n");
} }
TEST(FileTest, Close) { TEST(FileTest, Close) {
@ -495,4 +498,4 @@ TEST(LocaleTest, Strtod) {
EXPECT_EQ(start + 3, ptr); EXPECT_EQ(start + 3, ptr);
} }
# endif # endif
#endif // FMT_USE_FCNTL #endif // FMT_USE_FCNTL

View File

@ -145,13 +145,13 @@ TEST(OStreamTest, WriteToOStream) {
} }
TEST(OStreamTest, WriteToOStreamMaxSize) { TEST(OStreamTest, WriteToOStreamMaxSize) {
std::size_t max_size = fmt::internal::max_value<std::size_t>(); size_t max_size = fmt::internal::max_value<size_t>();
std::streamsize max_streamsize = fmt::internal::max_value<std::streamsize>(); std::streamsize max_streamsize = fmt::internal::max_value<std::streamsize>();
if (max_size <= fmt::internal::to_unsigned(max_streamsize)) return; if (max_size <= fmt::internal::to_unsigned(max_streamsize)) return;
struct test_buffer : fmt::internal::buffer<char> { struct test_buffer : fmt::internal::buffer<char> {
explicit test_buffer(std::size_t size) { resize(size); } explicit test_buffer(size_t size) { resize(size); }
void grow(std::size_t) {} void grow(size_t) {}
} buffer(max_size); } buffer(max_size);
struct mock_streambuf : std::streambuf { struct mock_streambuf : std::streambuf {
@ -258,7 +258,7 @@ TEST(OStreamTest, DisableBuiltinOStreamOperators) {
struct explicitly_convertible_to_string_like { struct explicitly_convertible_to_string_like {
template <typename String, template <typename String,
typename = typename std::enable_if<std::is_constructible< typename = typename std::enable_if<std::is_constructible<
String, const char*, std::size_t>::value>::type> String, const char*, size_t>::value>::type>
explicit operator String() const { explicit operator String() const {
return String("foo", 3u); return String("foo", 3u);
} }

View File

@ -49,8 +49,8 @@ int pipe_count;
int fopen_count; int fopen_count;
int fclose_count; int fclose_count;
int fileno_count; int fileno_count;
std::size_t read_nbyte; size_t read_nbyte;
std::size_t write_nbyte; size_t write_nbyte;
bool sysconf_error; bool sysconf_error;
enum { NONE, MAX_SIZE, ERROR } fstat_sim; enum { NONE, MAX_SIZE, ERROR } fstat_sim;
@ -288,7 +288,7 @@ TEST(FileTest, ReadRetry) {
write_end.write("test", SIZE); write_end.write("test", SIZE);
write_end.close(); write_end.close();
char buffer[SIZE]; char buffer[SIZE];
std::size_t count = 0; size_t count = 0;
EXPECT_RETRY(count = read_end.read(buffer, SIZE), read, EXPECT_RETRY(count = read_end.read(buffer, SIZE), read,
"cannot read from file"); "cannot read from file");
EXPECT_EQ_POSIX(static_cast<std::streamsize>(SIZE), count); EXPECT_EQ_POSIX(static_cast<std::streamsize>(SIZE), count);
@ -298,7 +298,7 @@ TEST(FileTest, WriteRetry) {
file read_end, write_end; file read_end, write_end;
file::pipe(read_end, write_end); file::pipe(read_end, write_end);
enum { SIZE = 4 }; enum { SIZE = 4 };
std::size_t count = 0; size_t count = 0;
EXPECT_RETRY(count = write_end.write("test", SIZE), write, EXPECT_RETRY(count = write_end.write("test", SIZE), write,
"cannot write to file"); "cannot write to file");
write_end.close(); write_end.close();
@ -316,8 +316,8 @@ TEST(FileTest, ConvertReadCount) {
file read_end, write_end; file read_end, write_end;
file::pipe(read_end, write_end); file::pipe(read_end, write_end);
char c; char c;
std::size_t size = UINT_MAX; size_t size = UINT_MAX;
if (sizeof(unsigned) != sizeof(std::size_t)) ++size; if (sizeof(unsigned) != sizeof(size_t)) ++size;
read_count = 1; read_count = 1;
read_nbyte = 0; read_nbyte = 0;
EXPECT_THROW(read_end.read(&c, size), fmt::system_error); EXPECT_THROW(read_end.read(&c, size), fmt::system_error);
@ -329,8 +329,8 @@ TEST(FileTest, ConvertWriteCount) {
file read_end, write_end; file read_end, write_end;
file::pipe(read_end, write_end); file::pipe(read_end, write_end);
char c; char c;
std::size_t size = UINT_MAX; size_t size = UINT_MAX;
if (sizeof(unsigned) != sizeof(std::size_t)) ++size; if (sizeof(unsigned) != sizeof(size_t)) ++size;
write_count = 1; write_count = 1;
write_nbyte = 0; write_nbyte = 0;
EXPECT_THROW(write_end.write(&c, size), fmt::system_error); EXPECT_THROW(write_end.write(&c, size), fmt::system_error);

View File

@ -119,8 +119,7 @@ TEST(PrintfTest, InvalidArgIndex) {
EXPECT_THROW_MSG(test_sprintf(format("%{}$d", INT_MAX), 42), format_error, EXPECT_THROW_MSG(test_sprintf(format("%{}$d", INT_MAX), 42), format_error,
"argument not found"); "argument not found");
EXPECT_THROW_MSG(test_sprintf("%2$", 42), format_error, EXPECT_THROW_MSG(test_sprintf("%2$", 42), format_error, "argument not found");
"argument not found");
EXPECT_THROW_MSG(test_sprintf(format("%{}$d", BIG_NUM), 42), format_error, EXPECT_THROW_MSG(test_sprintf(format("%{}$d", BIG_NUM), 42), format_error,
"number is too big"); "number is too big");
} }
@ -222,8 +221,7 @@ TEST(PrintfTest, DynamicWidth) {
EXPECT_EQ("42 ", test_sprintf("%*d", -5, 42)); EXPECT_EQ("42 ", test_sprintf("%*d", -5, 42));
EXPECT_THROW_MSG(test_sprintf("%*d", 5.0, 42), format_error, EXPECT_THROW_MSG(test_sprintf("%*d", 5.0, 42), format_error,
"width is not integer"); "width is not integer");
EXPECT_THROW_MSG(test_sprintf("%*d"), format_error, EXPECT_THROW_MSG(test_sprintf("%*d"), format_error, "argument not found");
"argument not found");
EXPECT_THROW_MSG(test_sprintf("%*d", BIG_NUM, 42), format_error, EXPECT_THROW_MSG(test_sprintf("%*d", BIG_NUM, 42), format_error,
"number is too big"); "number is too big");
} }
@ -273,8 +271,7 @@ TEST(PrintfTest, DynamicPrecision) {
EXPECT_EQ("42", test_sprintf("%.*d", -5, 42)); EXPECT_EQ("42", test_sprintf("%.*d", -5, 42));
EXPECT_THROW_MSG(test_sprintf("%.*d", 5.0, 42), format_error, EXPECT_THROW_MSG(test_sprintf("%.*d", 5.0, 42), format_error,
"precision is not integer"); "precision is not integer");
EXPECT_THROW_MSG(test_sprintf("%.*d"), format_error, EXPECT_THROW_MSG(test_sprintf("%.*d"), format_error, "argument not found");
"argument not found");
EXPECT_THROW_MSG(test_sprintf("%.*d", BIG_NUM, 42), format_error, EXPECT_THROW_MSG(test_sprintf("%.*d", BIG_NUM, 42), format_error,
"number is too big"); "number is too big");
if (sizeof(long long) != sizeof(int)) { if (sizeof(long long) != sizeof(int)) {
@ -372,7 +369,7 @@ TEST(PrintfTest, Length) {
TestLength<long long>("ll"); TestLength<long long>("ll");
TestLength<unsigned long long>("ll"); TestLength<unsigned long long>("ll");
TestLength<intmax_t>("j"); TestLength<intmax_t>("j");
TestLength<std::size_t>("z"); TestLength<size_t>("z");
TestLength<std::ptrdiff_t>("t"); TestLength<std::ptrdiff_t>("t");
long double max = max_value<long double>(); long double max = max_value<long double>();
EXPECT_PRINTF(fmt::format("{:.6}", max), "%g", max); EXPECT_PRINTF(fmt::format("{:.6}", max), "%g", max);

View File

@ -79,7 +79,7 @@ TEST(RangesTest, JoinInitializerList) {
struct my_struct { struct my_struct {
int32_t i; int32_t i;
std::string str; // can throw std::string str; // can throw
template <std::size_t N> decltype(auto) get() const noexcept { template <size_t N> decltype(auto) get() const noexcept {
if constexpr (N == 0) if constexpr (N == 0)
return i; return i;
else if constexpr (N == 1) else if constexpr (N == 1)
@ -87,16 +87,15 @@ struct my_struct {
} }
}; };
template <std::size_t N> decltype(auto) get(const my_struct& s) noexcept { template <size_t N> decltype(auto) get(const my_struct& s) noexcept {
return s.get<N>(); return s.get<N>();
} }
namespace std { namespace std {
template <> template <> struct tuple_size<my_struct> : std::integral_constant<size_t, 2> {};
struct tuple_size<my_struct> : std::integral_constant<std::size_t, 2> {};
template <std::size_t N> struct tuple_element<N, my_struct> { template <size_t N> struct tuple_element<N, my_struct> {
using type = decltype(std::declval<my_struct>().get<N>()); using type = decltype(std::declval<my_struct>().get<N>());
}; };

View File

@ -5,12 +5,14 @@
// //
// For the license information refer to format.h. // For the license information refer to format.h.
#include "scan.h"
#include <time.h> #include <time.h>
#include <climits> #include <climits>
#include "gmock.h" #include "gmock.h"
#include "gtest-extra.h" #include "gtest-extra.h"
#include "scan.h"
TEST(ScanTest, ReadText) { TEST(ScanTest, ReadText) {
fmt::string_view s = "foo"; fmt::string_view s = "foo";

View File

@ -1,4 +1,5 @@
#include <format> #include <format>
#include "gtest.h" #include "gtest.h"
TEST(StdFormatTest, Escaping) { TEST(StdFormatTest, Escaping) {

View File

@ -9,6 +9,7 @@
#define FMT_TEST_ASSERT_H_ #define FMT_TEST_ASSERT_H_
#include <stdexcept> #include <stdexcept>
#include "gtest.h" #include "gtest.h"
class assertion_failure : public std::logic_error { class assertion_failure : public std::logic_error {

View File

@ -6,6 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#include <cstdlib> #include <cstdlib>
#include "gtest.h" #include "gtest.h"
#ifdef _WIN32 #ifdef _WIN32

View File

@ -6,6 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#include "util.h" #include "util.h"
#include <cstring> #include <cstring>
void increment(char* s) { void increment(char* s) {

View File

@ -19,7 +19,7 @@ enum { BUFFER_SIZE = 256 };
# define FMT_VSNPRINTF vsnprintf # define FMT_VSNPRINTF vsnprintf
#endif #endif
template <std::size_t SIZE> template <size_t SIZE>
void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) { void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) {
std::va_list args; std::va_list args;
va_start(args, format); va_start(args, format);