From 79c7f8a70b8bc9ac65b29c001e29b9a029711ac4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 1 Sep 2025 10:45:14 -0700 Subject: [PATCH] Apply clang-tidy --- include/fmt/args.h | 2 +- include/fmt/base.h | 12 +++++++----- include/fmt/chrono.h | 6 +++--- include/fmt/compile.h | 6 +++--- include/fmt/format-inl.h | 10 +++++----- include/fmt/format.h | 10 +++++----- include/fmt/std.h | 5 ++--- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index d8fe241c..5e5f40f9 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -212,7 +212,7 @@ FMT_EXPORT template class dynamic_format_arg_store { } /// Returns the number of elements in the store. - size_t size() const noexcept { return data_.size(); } + auto size() const noexcept -> size_t { return data_.size(); } }; FMT_END_NAMESPACE diff --git a/include/fmt/base.h b/include/fmt/base.h index ecd7a855..efc8e999 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -458,8 +458,10 @@ enum { use_utf8 = !FMT_WIN32 || is_utf8_enabled }; static_assert(!FMT_UNICODE || use_utf8, "Unicode support requires compiling with /utf-8"); -template constexpr const char* narrow(const T*) { return nullptr; } -constexpr FMT_ALWAYS_INLINE const char* narrow(const char* s) { return s; } +template constexpr auto narrow(T*) -> char* { return nullptr; } +constexpr FMT_ALWAYS_INLINE auto narrow(const char* s) -> const char* { + return s; +} template FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, size_t n) -> int { @@ -762,7 +764,7 @@ class basic_specs { (static_cast(p) << precision_shift); } - constexpr bool dynamic() const { + constexpr auto dynamic() const -> bool { return (data_ & (width_mask | precision_mask)) != 0; } @@ -2369,8 +2371,8 @@ struct named_arg_store { } named_arg_store(const named_arg_store& rhs) = delete; - named_arg_store& operator=(const named_arg_store& rhs) = delete; - named_arg_store& operator=(named_arg_store&& rhs) = delete; + auto operator=(const named_arg_store& rhs) -> named_arg_store& = delete; + auto operator=(named_arg_store&& rhs) -> named_arg_store& = delete; operator const arg_t*() const { return args + 1; } }; diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index da40e70f..f9e3dd2b 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1000,16 +1000,16 @@ template struct has_tm_zone> : std::true_type {}; template ::value)> -bool set_tm_zone(T& time, char* tz) { +auto set_tm_zone(T& time, char* tz) -> bool { time.tm_zone = tz; return true; } template ::value)> -bool set_tm_zone(T&, char*) { +auto set_tm_zone(T&, char*) -> bool { return false; } -inline char* utc() { +inline auto utc() -> char* { static char tz[] = "UTC"; return tz; } diff --git a/include/fmt/compile.h b/include/fmt/compile.h index cb9f266e..f711ba41 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -43,7 +43,7 @@ struct is_compiled_string : std::is_base_of {}; * Converts a string literal into a format string that will be parsed at * compile time and converted into efficient formatting code. Requires support * for class types in constant template parameters (a C++20 feature). - * + * * **Example**: * * // Converts 42 into std::string using the most efficient method and no @@ -71,8 +71,8 @@ template struct type_list {}; // Returns a reference to the argument at index N from [first, rest...]. template -constexpr const auto& get([[maybe_unused]] const T& first, - [[maybe_unused]] const Args&... rest) { +constexpr auto get([[maybe_unused]] const T& first, + [[maybe_unused]] const Args&... rest) -> const auto& { static_assert(N < 1 + sizeof...(Args), "index is out of bounds"); if constexpr (N == 0) return first; diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 6737e1d0..88725972 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1162,7 +1162,7 @@ auto is_left_endpoint_integer_shorter_interval(int exponent) noexcept -> bool { } // Remove trailing zeros from n and return the number of zeros removed (float). -FMT_INLINE int remove_trailing_zeros(uint32_t& n, int s = 0) noexcept { +FMT_INLINE auto remove_trailing_zeros(uint32_t& n, int s = 0) noexcept -> int { FMT_ASSERT(n != 0, ""); // Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1. constexpr uint32_t mod_inv_5 = 0xcccccccd; @@ -1183,7 +1183,7 @@ FMT_INLINE int remove_trailing_zeros(uint32_t& n, int s = 0) noexcept { } // Removes trailing zeros and returns the number of zeros removed (double). -FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept { +FMT_INLINE auto remove_trailing_zeros(uint64_t& n) noexcept -> int { FMT_ASSERT(n != 0, ""); // Is n is divisible by 10^8? @@ -1219,7 +1219,7 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept { // The main algorithm for shorter interval case template -FMT_INLINE decimal_fp shorter_interval_case(int exponent) noexcept { +FMT_INLINE auto shorter_interval_case(int exponent) noexcept -> decimal_fp { decimal_fp ret_value; // Compute k and beta const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent); @@ -1555,7 +1555,7 @@ template class glibc_file : public file_base { void advance_write_buffer(size_t size) { this->file_->_IO_write_ptr += size; } - bool needs_flush() const { + auto needs_flush() const -> bool { if ((this->file_->_flags & line_buffered) == 0) return false; char* end = this->file_->_IO_write_end; auto size = max_of(this->file_->_IO_write_ptr - end, 0); @@ -1604,7 +1604,7 @@ template class apple_file : public file_base { this->file_->_w -= size; } - bool needs_flush() const { + auto needs_flush() const -> bool { if ((this->file_->_flags & line_buffered) == 0) return false; return memchr(this->file_->_p + this->file_->_w, '\n', to_unsigned(-this->file_->_w)); diff --git a/include/fmt/format.h b/include/fmt/format.h index b766c08b..634e18a4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -736,7 +736,7 @@ using is_double_double = bool_constant::digits == 106>; template struct allocator : private std::decay { using value_type = T; - T* allocate(size_t n) { + auto allocate(size_t n) -> T* { FMT_ASSERT(n <= max_value() / sizeof(T), ""); T* p = static_cast(std::malloc(n * sizeof(T))); if (!p) FMT_THROW(std::bad_alloc()); @@ -940,7 +940,7 @@ class string_buffer { inline string_buffer() : buf_(str_) {} inline operator writer() { return buf_; } - inline std::string& str() { return str_; } + inline auto str() -> std::string& { return str_; } }; template @@ -2622,7 +2622,7 @@ FMT_CONSTEXPR auto isfinite(T value) -> bool { } template ::value)> -FMT_INLINE FMT_CONSTEXPR bool signbit(T value) { +FMT_INLINE FMT_CONSTEXPR auto signbit(T value) -> bool { if (is_constant_evaluated()) { #ifdef __cpp_if_constexpr if constexpr (std::numeric_limits::is_iec559) { @@ -3698,9 +3698,9 @@ FMT_CONSTEXPR auto get_arg(Context& ctx, ID id) -> basic_format_arg { } template -FMT_CONSTEXPR int get_dynamic_spec( +FMT_CONSTEXPR auto get_dynamic_spec( arg_id_kind kind, const arg_ref& ref, - Context& ctx) { + Context& ctx) -> int { FMT_ASSERT(kind != arg_id_kind::none, ""); auto arg = kind == arg_id_kind::index ? ctx.arg(ref.index) : ctx.arg(ref.name); diff --git a/include/fmt/std.h b/include/fmt/std.h index 9b3709f5..6681db3a 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -129,9 +129,8 @@ struct is_variant_like_> : std::true_type {}; template class is_variant_formattable { template - static std::conjunction< - is_formattable, Char>...> - check(std::index_sequence); + static auto check(std::index_sequence) -> std::conjunction< + is_formattable, Char>...>; public: static constexpr bool value = decltype(check(