Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy fixes #1397

Merged
merged 9 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
#endif

#ifndef FMT_ASSERT
# define FMT_ASSERT(condition, message) assert((condition) && message)
# define FMT_ASSERT(condition, message) assert((condition) && (message))
#endif

// libc++ supports string_view in pre-c++17.
Expand Down Expand Up @@ -437,8 +437,8 @@ template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
};

struct error_handler {
FMT_CONSTEXPR error_handler() {}
FMT_CONSTEXPR error_handler(const error_handler&) {}
FMT_CONSTEXPR error_handler() = default;
FMT_CONSTEXPR error_handler(const error_handler&) = default;

// This function is intentionally not constexpr to give a compile-time error.
FMT_NORETURN FMT_API void on_error(const char* message);
Expand Down Expand Up @@ -552,9 +552,6 @@ using has_formatter =
/** A contiguous memory buffer with an optional growing ability. */
template <typename T> class buffer {
private:
buffer(const buffer&) = delete;
void operator=(const buffer&) = delete;

T* ptr_;
std::size_t size_;
std::size_t capacity_;
Expand All @@ -581,7 +578,9 @@ template <typename T> class buffer {
using value_type = T;
using const_reference = const T&;

virtual ~buffer() {}
buffer(const buffer&) = delete;
void operator=(const buffer&) = delete;
virtual ~buffer() = default;

T* begin() FMT_NOEXCEPT { return ptr_; }
T* end() FMT_NOEXCEPT { return ptr_ + size_; }
Expand Down Expand Up @@ -920,7 +919,7 @@ using mapped_type_constant =
enum { packed_arg_bits = 5 };
// Maximum number of arguments with packed types.
enum { max_packed_args = 63 / packed_arg_bits };
enum : unsigned long long { is_unpacked_bit = 1ull << 63 };
enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };

template <typename Context> class arg_map;
} // namespace internal
Expand Down Expand Up @@ -1035,9 +1034,6 @@ namespace internal {
// A map from argument names to their values for named arguments.
template <typename Context> class arg_map {
private:
arg_map(const arg_map&) = delete;
void operator=(const arg_map&) = delete;

using char_type = typename Context::char_type;

struct entry {
Expand All @@ -1055,6 +1051,8 @@ template <typename Context> class arg_map {
}

public:
arg_map(const arg_map&) = delete;
void operator=(const arg_map&) = delete;
arg_map() : map_(nullptr), size_(0) {}
void init(const basic_format_args<Context>& args);
~arg_map() { delete[] map_; }
Expand Down Expand Up @@ -1121,14 +1119,13 @@ template <typename OutputIt, typename Char> class basic_format_context {
internal::arg_map<basic_format_context> map_;
internal::locale_ref loc_;

basic_format_context(const basic_format_context&) = delete;
void operator=(const basic_format_context&) = delete;

public:
using iterator = OutputIt;
using format_arg = basic_format_arg<basic_format_context>;
template <typename T> using formatter_type = formatter<T, char_type>;

basic_format_context(const basic_format_context&) = delete;
void operator=(const basic_format_context&) = delete;
/**
Constructs a ``basic_format_context`` object. References to the arguments are
stored in the object so make sure they have appropriate lifetimes.
Expand Down
40 changes: 20 additions & 20 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "format.h"

#include <string.h>
#include <cstring>

#include <cctype>
#include <cerrno>
Expand Down Expand Up @@ -56,10 +56,10 @@
// Dummy implementations of strerror_r and strerror_s called if corresponding
// system functions are not available.
inline fmt::internal::null<> strerror_r(int, char*, ...) {
return fmt::internal::null<>();
return {};
}
inline fmt::internal::null<> strerror_s(char*, std::size_t, ...) {
return fmt::internal::null<>();
return {};
}

FMT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -232,8 +232,8 @@ FMT_FUNC Char internal::decimal_point_impl(locale_ref) {
}
#endif

FMT_API FMT_FUNC format_error::~format_error() FMT_NOEXCEPT {}
FMT_API FMT_FUNC system_error::~system_error() FMT_NOEXCEPT {}
FMT_API FMT_FUNC format_error::~format_error() FMT_NOEXCEPT = default;
FMT_API FMT_FUNC system_error::~system_error() FMT_NOEXCEPT = default;

FMT_FUNC void system_error::init(int err_code, string_view format_str,
format_args args) {
Expand Down Expand Up @@ -280,23 +280,23 @@ template <typename T>
const char basic_data<T>::hex_digits[] = "0123456789abcdef";

#define FMT_POWERS_OF_10(factor) \
factor * 10, factor * 100, factor * 1000, factor * 10000, factor * 100000, \
factor * 1000000, factor * 10000000, factor * 100000000, \
factor * 1000000000
factor * 10, (factor) * 100, (factor) * 1000, (factor) * 10000, (factor) * 100000, \
(factor) * 1000000, (factor) * 10000000, (factor) * 100000000, \
(factor) * 1000000000

template <typename T>
const uint64_t basic_data<T>::powers_of_10_64[] = {
1, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ull),
10000000000000000000ull};
1, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ULL),
10000000000000000000ULL};

template <typename T>
const uint32_t basic_data<T>::zero_or_powers_of_10_32[] = {0,
FMT_POWERS_OF_10(1)};

template <typename T>
const uint64_t basic_data<T>::zero_or_powers_of_10_64[] = {
0, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ull),
10000000000000000000ull};
0, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ULL),
10000000000000000000ULL};

// Normalized 64-bit significands of pow(10, k), for k = -348, -340, ..., 340.
// These are generated by support/compute-powers.py.
Expand Down Expand Up @@ -373,7 +373,7 @@ class fp {
static FMT_CONSTEXPR_DECL const int double_significand_size =
std::numeric_limits<double>::digits - 1;
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit =
1ull << double_significand_size;
1ULL << double_significand_size;

public:
significand_type f;
Expand Down Expand Up @@ -412,7 +412,7 @@ class fp {
const int exponent_size =
bits<Double>::value - double_significand_size - 1; // -1 for sign
const uint64_t significand_mask = implicit_bit - 1;
const uint64_t exponent_mask = (~0ull >> 1) & ~significand_mask;
const uint64_t exponent_mask = (~0ULL >> 1) & ~significand_mask;
const int exponent_bias = (1 << exponent_size) - limits::max_exponent - 1;
auto u = bit_cast<uint64_t>(d);
f = u & significand_mask;
Expand Down Expand Up @@ -463,7 +463,7 @@ inline bool operator==(fp x, fp y) { return x.f == y.f && x.e == y.e; }
// Returns an fp number representing x - y. Result may not be normalized.
inline fp operator-(fp x, fp y) {
FMT_ASSERT(x.f >= y.f && x.e == y.e, "invalid operands");
return fp(x.f - y.f, x.e);
return {x.f - y.f, x.e};
}

// Computes an fp number r with r.f = x.f * y.f / pow(2, 64) rounded to nearest
Expand All @@ -475,7 +475,7 @@ FMT_FUNC fp operator*(fp x, fp y) {
auto product = static_cast<__uint128_t>(x.f) * y.f;
auto f = static_cast<uint64_t>(product >> 64);
if ((static_cast<uint64_t>(product) & (1ULL << 63)) != 0) ++f;
return fp(f, exp);
return {f, exp};
#else
// Multiply 32-bit parts of significands.
uint64_t mask = (1ULL << 32) - 1;
Expand Down Expand Up @@ -505,7 +505,7 @@ FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) {
const int dec_exp_step = 8;
index = (index - first_dec_exp - 1) / dec_exp_step + 1;
pow10_exponent = first_dec_exp + index * dec_exp_step;
return fp(data::pow10_significands[index], data::pow10_exponents[index]);
return {data::pow10_significands[index], data::pow10_exponents[index]};
}

// A simple accumulator to hold the sums of terms in bigint::square if uint128_t
Expand Down Expand Up @@ -796,11 +796,11 @@ enum result {
template <typename Handler>
FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
int& exp, Handler& handler) {
const fp one(1ull << -value.e, value.e);
const fp one(1ULL << -value.e, value.e);
// The integral part of scaled value (p1 in Grisu) = value / one. It cannot be
// zero because it contains a product of two 64-bit numbers with MSB set (due
// to normalization) - 1, shifted right by at most 60 bits.
uint32_t integral = static_cast<uint32_t>(value.f >> -one.e);
auto integral = static_cast<uint32_t>(value.f >> -one.e);
FMT_ASSERT(integral != 0, "");
FMT_ASSERT(integral == value.f >> -one.e, "");
// The fractional part of scaled value (p2 in Grisu) c = value % one.
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void fallback_format(Double d, buffer<char>& buf, int& exp10) {
denominator <<= shift - value.e;
lower.assign(1);
if (shift != 1) {
upper_store.assign(1ull << 1);
upper_store.assign(1ULL << 1);
upper = &upper_store;
}
}
Expand Down
26 changes: 13 additions & 13 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class basic_memory_buffer : private Allocator, public internal::buffer<T> {
: Allocator(alloc) {
this->set(store_, SIZE);
}
~basic_memory_buffer() { deallocate(); }
~basic_memory_buffer() FMT_OVERRIDE { deallocate(); }

private:
// Move data from other to this buffer.
Expand Down Expand Up @@ -607,14 +607,14 @@ class basic_memory_buffer : private Allocator, public internal::buffer<T> {
of the other object to it.
\endrst
*/
basic_memory_buffer(basic_memory_buffer&& other) { move(other); }
basic_memory_buffer(basic_memory_buffer&& other) FMT_NOEXCEPT { move(other); }

/**
\rst
Moves the content of the other ``basic_memory_buffer`` object to this one.
\endrst
*/
basic_memory_buffer& operator=(basic_memory_buffer&& other) {
basic_memory_buffer& operator=(basic_memory_buffer&& other) FMT_NOEXCEPT {
assert(this != &other);
deallocate();
move(other);
Expand Down Expand Up @@ -658,7 +658,7 @@ class FMT_API format_error : public std::runtime_error {
format_error& operator=(const format_error&) = default;
format_error(format_error&&) = default;
format_error& operator=(format_error&&) = default;
~format_error() FMT_NOEXCEPT;
~format_error() FMT_NOEXCEPT FMT_OVERRIDE;
};

namespace internal {
Expand Down Expand Up @@ -740,7 +740,7 @@ inline int count_digits(uint128_t n) {
if (n < 100) return count + 1;
if (n < 1000) return count + 2;
if (n < 10000) return count + 3;
n /= 10000u;
n /= 10000U;
count += 4;
}
}
Expand Down Expand Up @@ -862,7 +862,7 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits,
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned index = static_cast<unsigned>((value % 100) * 2);
auto index = static_cast<unsigned>((value % 100) * 2);
value /= 100;
*--buffer = static_cast<Char>(data::digits[index + 1]);
add_thousands_sep(buffer);
Expand All @@ -873,7 +873,7 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits,
*--buffer = static_cast<Char>('0' + value);
return end;
}
unsigned index = static_cast<unsigned>(value * 2);
auto index = static_cast<unsigned>(value * 2);
*--buffer = static_cast<Char>(data::digits[index + 1]);
add_thousands_sep(buffer);
*--buffer = static_cast<Char>(data::digits[index]);
Expand Down Expand Up @@ -1568,7 +1568,7 @@ template <typename Range> class basic_writer {
void on_num() {
std::string groups = internal::grouping<char_type>(writer.locale_);
if (groups.empty()) return on_dec();
char_type sep = internal::thousands_sep<char_type>(writer.locale_);
auto sep = internal::thousands_sep<char_type>(writer.locale_);
if (!sep) return on_dec();
int num_digits = internal::count_digits(abs_value);
int size = num_digits;
Expand Down Expand Up @@ -2752,7 +2752,7 @@ class FMT_API system_error : public std::runtime_error {
system_error& operator=(const system_error&) = default;
system_error(system_error&&) = default;
system_error& operator=(system_error&&) = default;
~system_error() FMT_NOEXCEPT;
~system_error() FMT_NOEXCEPT FMT_OVERRIDE;

int error_code() const { return error_code_; }
};
Expand Down Expand Up @@ -2965,7 +2965,7 @@ class format_int {
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned index = static_cast<unsigned>((value % 100) * 2);
auto index = static_cast<unsigned>((value % 100) * 2);
value /= 100;
*--ptr = internal::data::digits[index + 1];
*--ptr = internal::data::digits[index];
Expand All @@ -2974,14 +2974,14 @@ class format_int {
*--ptr = static_cast<char>('0' + value);
return ptr;
}
unsigned index = static_cast<unsigned>(value * 2);
auto index = static_cast<unsigned>(value * 2);
*--ptr = internal::data::digits[index + 1];
*--ptr = internal::data::digits[index];
return ptr;
}

void format_signed(long long value) {
unsigned long long abs_value = static_cast<unsigned long long>(value);
auto abs_value = static_cast<unsigned long long>(value);
bool negative = value < 0;
if (negative) abs_value = 0 - abs_value;
str_ = format_decimal(abs_value);
Expand Down Expand Up @@ -3030,7 +3030,7 @@ template <typename T, typename Char>
struct formatter<T, Char,
enable_if_t<internal::type_constant<T, Char>::value !=
internal::custom_type>> {
FMT_CONSTEXPR formatter() {}
FMT_CONSTEXPR formatter() = default;

// Parses format specifiers stopping either at the end of the range or at the
// terminating '}'.
Expand Down
Loading