From 448929d491329d67ebe47786195ddcf2c3bcb922 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 3 May 2025 07:29:09 -0700 Subject: [PATCH] Update and apply clang-format --- .clang-format | 1 + include/fmt/format-inl.h | 2 +- test/base-test.cc | 15 +++++++-------- test/format-test.cc | 8 +++++--- test/no-builtin-types-test.cc | 4 ++-- test/ranges-test.cc | 14 +++++++------- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.clang-format b/.clang-format index 31f8c343..08fa7ba8 100644 --- a/.clang-format +++ b/.clang-format @@ -7,6 +7,7 @@ IndentCaseLabels: false AlwaysBreakTemplateDeclarations: false DerivePointerAlignment: false AllowShortCaseLabelsOnASingleLine: true +QualifierAlignment: Left AlignConsecutiveShortCaseStatements: Enabled: true AcrossEmptyLines: true diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 46f949ea..a1e01661 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1097,7 +1097,7 @@ template <> struct cache_accessor { return {r.high(), r.low() == 0}; } - static auto compute_delta(cache_entry_type const& cache, int beta) noexcept + static auto compute_delta(const cache_entry_type& cache, int beta) noexcept -> uint32_t { return static_cast(cache.high() >> (64 - 1 - beta)); } diff --git a/test/base-test.cc b/test/base-test.cc index 0d8ae91b..c55c89a0 100644 --- a/test/base-test.cc +++ b/test/base-test.cc @@ -95,18 +95,17 @@ TEST(string_view_test, compare) { #if FMT_USE_CONSTEVAL namespace { -template -struct fixed_string { - char data[N] = {}; +template struct fixed_string { + char data[N] = {}; - constexpr fixed_string(char const (&m)[N]) { - for (size_t i = 0; i != N; ++i) { - data[i] = m[i]; - } + constexpr fixed_string(const char (&m)[N]) { + for (size_t i = 0; i != N; ++i) { + data[i] = m[i]; } + } }; -} +} // namespace TEST(string_view_test, from_constexpr_fixed_string) { static constexpr auto fs = fixed_string<5>("x={}"); diff --git a/test/format-test.cc b/test/format-test.cc index 839cadfe..0d931e4b 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -583,7 +583,8 @@ TEST(format_test, named_arg) { fmt::arg("A_", "A"), fmt::arg("_1", 1))); EXPECT_EQ(fmt::format("{0:{width}}", -42, fmt::arg("width", 4)), " -42"); EXPECT_EQ(fmt::format("{value:{width}}", fmt::arg("value", -42), - fmt::arg("width", 4)), " -42"); + fmt::arg("width", 4)), + " -42"); EXPECT_EQ("st", fmt::format("{0:.{precision}}", "str", fmt::arg("precision", 2))); EXPECT_EQ(fmt::format("{} {two}", 1, fmt::arg("two", 2)), "1 2"); @@ -601,8 +602,9 @@ TEST(format_test, named_arg) { EXPECT_THROW_MSG((void)fmt::format(runtime("{a} {}"), fmt::arg("a", 2), 42), format_error, "cannot switch from manual to automatic argument indexing"); - EXPECT_THROW_MSG((void)fmt::format("{a}", fmt::arg("a", 1), - fmt::arg("a", 10)), format_error, "duplicate named arg"); + EXPECT_THROW_MSG( + (void)fmt::format("{a}", fmt::arg("a", 1), fmt::arg("a", 10)), + format_error, "duplicate named arg"); } TEST(format_test, auto_arg_index) { diff --git a/test/no-builtin-types-test.cc b/test/no-builtin-types-test.cc index a0d0bda3..75c7fd16 100644 --- a/test/no-builtin-types-test.cc +++ b/test/no-builtin-types-test.cc @@ -8,8 +8,8 @@ #include "gtest/gtest.h" #if !defined(__GNUC__) || __GNUC__ >= 5 -#define FMT_BUILTIN_TYPES 0 -#include "fmt/format.h" +# define FMT_BUILTIN_TYPES 0 +# include "fmt/format.h" TEST(no_builtin_types_test, format) { EXPECT_EQ(fmt::format("{}", 42), "42"); diff --git a/test/ranges-test.cc b/test/ranges-test.cc index e1c1f3ec..d65037fa 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -330,7 +330,7 @@ template class noncopyable_range { explicit noncopyable_range(Args&&... args) : vec(std::forward(args)...) {} - noncopyable_range(noncopyable_range const&) = delete; + noncopyable_range(const noncopyable_range&) = delete; noncopyable_range(noncopyable_range&) = delete; auto begin() -> iterator { return vec.begin(); } @@ -424,7 +424,7 @@ TEST(ranges_test, join_tuple) { auto t5 = tuple_like{42, "foo"}; EXPECT_EQ(fmt::format("{}", fmt::join(t5, ", ")), "42, foo"); -# if FMT_TUPLE_JOIN_SPECIFIERS +#if FMT_TUPLE_JOIN_SPECIFIERS // Specs applied to each element. auto t5 = std::tuple(-3, 100, 1); EXPECT_EQ(fmt::format("{:+03}", fmt::join(t5, ", ")), "-03, +100, +01"); @@ -437,7 +437,7 @@ TEST(ranges_test, join_tuple) { int y = -1; auto t7 = std::tuple(3, y, y); EXPECT_EQ(fmt::format("{:03}", fmt::join(t7, ", ")), "003, -01, -01"); -# endif +#endif } TEST(ranges_test, join_initializer_list) { @@ -457,7 +457,7 @@ struct zstring { auto end() const -> zstring_sentinel { return {}; } }; -# ifdef __cpp_lib_ranges +#ifdef __cpp_lib_ranges struct cpp20_only_range { struct iterator { int val = 0; @@ -487,7 +487,7 @@ struct cpp20_only_range { }; static_assert(std::input_iterator); -# endif +#endif TEST(ranges_test, join_sentinel) { auto hello = zstring{"hello"}; @@ -515,13 +515,13 @@ TEST(ranges_test, join_range) { const auto z = std::vector(3u, 0); EXPECT_EQ(fmt::format("{}", fmt::join(z, ",")), "0,0,0"); -# ifdef __cpp_lib_ranges +#ifdef __cpp_lib_ranges EXPECT_EQ(fmt::format("{}", cpp20_only_range{.lo = 0, .hi = 5}), "[0, 1, 2, 3, 4]"); EXPECT_EQ( fmt::format("{}", fmt::join(cpp20_only_range{.lo = 0, .hi = 5}, ",")), "0,1,2,3,4"); -# endif +#endif } namespace adl {