From e904e891bd17ff367149fb4daf9af6d2e5100ace Mon Sep 17 00:00:00 2001 From: Jonathan Gopel Date: Tue, 27 Oct 2020 21:55:44 -0600 Subject: [PATCH] :art: :bug: Rename all shadowed types and variables --- include/fmt/compile.h | 16 ++++++++-------- include/fmt/os.h | 4 ++-- test/chrono-test.cc | 4 ++-- test/core-test.cc | 14 +++++++------- test/format-test.cc | 28 ++++++++++++++-------------- test/locale-test.cc | 12 +++++------- test/ostream-test.cc | 5 +++-- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 3a33b020..db562ce4 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -175,9 +175,9 @@ class format_string_compiler : public error_handler { repl.arg_id = part_.part_kind == part::kind::arg_index ? arg_ref(part_.val.arg_index) : arg_ref(part_.val.str); - auto part = part::make_replacement(repl); - part.arg_id_end = begin; - handler_(part); + auto replacement_part = part::make_replacement(repl); + replacement_part.arg_id_end = begin; + handler_(replacement_part); return it; } }; @@ -530,14 +530,14 @@ constexpr auto compile_format_string(S format_str) { if constexpr (str[POS + 1] == '{') { return parse_tail(make_text(str, POS, 1), format_str); } else if constexpr (str[POS + 1] == '}') { - using type = get_type; - return parse_tail(field(), + using id_type = get_type; + return parse_tail(field(), format_str); } else if constexpr (str[POS + 1] == ':') { - using type = get_type; - constexpr auto result = parse_specs(str, POS + 2, ID); + using id_type = get_type; + constexpr auto result = parse_specs(str, POS + 2, ID); return parse_tail( - spec_field{result.fmt}, format_str); + spec_field{result.fmt}, format_str); } else { return unknown_format(); } diff --git a/include/fmt/os.h b/include/fmt/os.h index 88151006..7e181c86 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -363,8 +363,8 @@ struct ostream_params { ostream_params() {} template - ostream_params(T... params, int oflag) : ostream_params(params...) { - this->oflag = oflag; + ostream_params(T... params, int new_oflag) : ostream_params(params...) { + oflag = new_oflag; } template diff --git a/test/chrono-test.cc b/test/chrono-test.cc index fa383c14..359001a5 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -108,8 +108,8 @@ TEST(TimeTest, TimePoint) { #define EXPECT_TIME(spec, time, duration) \ { \ - std::locale loc("ja_JP.utf8"); \ - EXPECT_EQ(format_tm(time, spec, loc), \ + std::locale jp_loc("ja_JP.utf8"); \ + EXPECT_EQ(format_tm(time, spec, jp_loc), \ fmt::format(loc, "{:" spec "}", duration)); \ } diff --git a/test/core-test.cc b/test/core-test.cc index 9d88070d..67456399 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -83,8 +83,8 @@ template struct mock_buffer final : buffer { void grow(size_t capacity) { this->set(this->data(), do_grow(capacity)); } - mock_buffer(T* data = nullptr, size_t capacity = 0) { - this->set(data, capacity); + mock_buffer(T* data = nullptr, size_t buf_capacity = 0) { + this->set(data, buf_capacity); ON_CALL(*this, do_grow(_)).WillByDefault(Invoke([](size_t capacity) { return capacity; })); @@ -224,9 +224,9 @@ struct custom_context { }; bool called; - fmt::format_parse_context ctx; + fmt::format_parse_context parse_ctx; - fmt::format_parse_context& parse_context() { return ctx; } + fmt::format_parse_context& parse_context() { return parse_ctx; } void advance_to(const char*) {} }; @@ -688,9 +688,9 @@ TYPED_TEST(IsStringTest, IsString) { EXPECT_TRUE(fmt::detail::is_string>::value); EXPECT_TRUE( fmt::detail::is_string>::value); - using string_view = fmt::detail::std_string_view; - EXPECT_TRUE(std::is_empty::value != - fmt::detail::is_string::value); + using fmt_string_view = fmt::detail::std_string_view; + EXPECT_TRUE(std::is_empty::value != + fmt::detail::is_string::value); EXPECT_TRUE(fmt::detail::is_string>::value); EXPECT_FALSE(fmt::detail::is_string::value); } diff --git a/test/format-test.cc b/test/format-test.cc index 4d8f90ea..2f12bd15 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -219,12 +219,12 @@ TEST(AllocatorTest, allocator_ref) { check_forwarding(alloc, ref3); } -typedef allocator_ref> TestAllocator; +typedef allocator_ref> std_allocator; static void check_move_buffer( - const char* str, basic_memory_buffer& buffer) { + const char* str, basic_memory_buffer& buffer) { std::allocator* alloc = buffer.get_allocator().get(); - basic_memory_buffer buffer2(std::move(buffer)); + basic_memory_buffer buffer2(std::move(buffer)); // Move shouldn't destroy the inline content of the first buffer. EXPECT_EQ(str, std::string(&buffer[0], buffer.size())); EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size())); @@ -236,7 +236,7 @@ static void check_move_buffer( TEST(MemoryBufferTest, MoveCtorInlineBuffer) { std::allocator alloc; - basic_memory_buffer buffer((TestAllocator(&alloc))); + basic_memory_buffer buffer((std_allocator(&alloc))); const char test[] = "test"; buffer.append(string_view(test, 4)); check_move_buffer("test", buffer); @@ -248,14 +248,14 @@ TEST(MemoryBufferTest, MoveCtorInlineBuffer) { TEST(MemoryBufferTest, MoveCtorDynamicBuffer) { std::allocator alloc; - basic_memory_buffer buffer((TestAllocator(&alloc))); + basic_memory_buffer buffer((std_allocator(&alloc))); const char test[] = "test"; buffer.append(test, test + 4); const char* inline_buffer_ptr = &buffer[0]; // Adding one more character causes the content to move from the inline to // a dynamically allocated buffer. buffer.push_back('a'); - basic_memory_buffer buffer2(std::move(buffer)); + basic_memory_buffer buffer2(std::move(buffer)); // Move should rip the guts of the first buffer. EXPECT_EQ(inline_buffer_ptr, &buffer[0]); EXPECT_EQ("testa", std::string(&buffer2[0], buffer2.size())); @@ -446,9 +446,9 @@ TEST(UtilTest, FormatSystemError) { } TEST(UtilTest, SystemError) { - fmt::system_error e(EDOM, "test"); - EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)), e.what()); - EXPECT_EQ(EDOM, e.error_code()); + fmt::system_error test_error(EDOM, "test"); + EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)), test_error.what()); + EXPECT_EQ(EDOM, test_error.error_code()); fmt::system_error error(0, ""); try { @@ -2097,7 +2097,7 @@ struct test_format_specs_handler { enum Result { NONE, PLUS, MINUS, SPACE, HASH, ZERO, ERROR }; Result res = NONE; - fmt::align_t align = fmt::align::none; + fmt::align_t alignment = fmt::align::none; char fill = 0; int width = 0; fmt::detail::arg_ref width_ref; @@ -2111,7 +2111,7 @@ struct test_format_specs_handler { FMT_CONSTEXPR test_format_specs_handler( const test_format_specs_handler& other) : res(other.res), - align(other.align), + alignment(other.alignment), fill(other.fill), width(other.width), width_ref(other.width_ref), @@ -2119,7 +2119,7 @@ struct test_format_specs_handler { precision_ref(other.precision_ref), type(other.type) {} - FMT_CONSTEXPR void on_align(fmt::align_t a) { align = a; } + FMT_CONSTEXPR void on_align(fmt::align_t a) { alignment = a; } FMT_CONSTEXPR void on_fill(fmt::string_view f) { fill = f[0]; } FMT_CONSTEXPR void on_plus() { res = PLUS; } FMT_CONSTEXPR void on_minus() { res = MINUS; } @@ -2151,7 +2151,7 @@ FMT_CONSTEXPR test_format_specs_handler parse_test_specs(const char (&s)[N]) { TEST(FormatTest, ConstexprParseFormatSpecs) { typedef test_format_specs_handler handler; - static_assert(parse_test_specs("<").align == fmt::align::left, ""); + static_assert(parse_test_specs("<").alignment == fmt::align::left, ""); static_assert(parse_test_specs("*^").fill == '*', ""); static_assert(parse_test_specs("+").res == handler::PLUS, ""); static_assert(parse_test_specs("-").res == handler::MINUS, ""); @@ -2262,7 +2262,7 @@ FMT_CONSTEXPR test_format_specs_handler check_specs(const char (&s)[N]) { TEST(FormatTest, ConstexprSpecsChecker) { typedef test_format_specs_handler handler; - static_assert(check_specs("<").align == fmt::align::left, ""); + static_assert(check_specs("<").alignment == fmt::align::left, ""); static_assert(check_specs("*^").fill == '*', ""); static_assert(check_specs("+").res == handler::PLUS, ""); static_assert(check_specs("-").res == handler::MINUS, ""); diff --git a/test/locale-test.cc b/test/locale-test.cc index c7c30f2e..672c6b28 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -131,15 +131,13 @@ template struct formatter, charT> { FormatContext& ctx) { detail::handle_dynamic_spec( specs_.precision, specs_.precision_ref, ctx); - auto format_specs = std::string(); - if (specs_.precision > 0) - format_specs = fmt::format(".{}", specs_.precision); - if (specs_.type) - format_specs += specs_.type; + auto specs = std::string(); + if (specs_.precision > 0) specs = fmt::format(".{}", specs_.precision); + if (specs_.type) specs += specs_.type; auto real = fmt::format(ctx.locale().template get(), - "{:" + format_specs + "}", c.real()); + "{:" + specs + "}", c.real()); auto imag = fmt::format(ctx.locale().template get(), - "{:" + format_specs + "}", c.imag()); + "{:" + specs + "}", c.imag()); auto fill_align_width = std::string(); if (specs_.width > 0) fill_align_width = fmt::format(">{}", specs_.width); diff --git a/test/ostream-test.cc b/test/ostream-test.cc index ebf14210..ec9508e3 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -152,7 +152,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) { struct test_buffer final : fmt::detail::buffer { explicit test_buffer(size_t size) - : fmt::detail::buffer(nullptr, size, size) {} + : fmt::detail::buffer(nullptr, size, size) {} void grow(size_t) {} } buffer(max_size); @@ -165,7 +165,8 @@ TEST(OStreamTest, WriteToOStreamMaxSize) { } streambuf; struct test_ostream : std::ostream { - explicit test_ostream(mock_streambuf& buffer) : std::ostream(&buffer) {} + explicit test_ostream(mock_streambuf& output_buffer) + : std::ostream(&output_buffer) {} } os(streambuf); testing::InSequence sequence;