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

Rename all shadowed types and variables and enable Wshadow when in pedantic mode #1965

Merged
merged 2 commits into from
Nov 3, 2020
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
-Wvector-operation-performance -Wsized-deallocation)
-Wvector-operation-performance -Wsized-deallocation -Wshadow)
endif ()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
Expand All @@ -130,7 +130,7 @@ endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef
-Wdeprecated -Wweak-vtables)
-Wdeprecated -Wweak-vtables -Wshadow)
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING)
if (HAS_NULLPTR_WARNING)
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
Expand Down
16 changes: 8 additions & 8 deletions include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class format_string_compiler : public error_handler {
repl.arg_id = part_.part_kind == part::kind::arg_index
? arg_ref<Char>(part_.val.arg_index)
: arg_ref<Char>(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;
}
};
Expand Down Expand Up @@ -530,14 +530,14 @@ constexpr auto compile_format_string(S format_str) {
if constexpr (str[POS + 1] == '{') {
return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
} else if constexpr (str[POS + 1] == '}') {
using type = get_type<ID, Args>;
return parse_tail<Args, POS + 2, ID + 1>(field<char_type, type, ID>(),
using id_type = get_type<ID, Args>;
return parse_tail<Args, POS + 2, ID + 1>(field<char_type, id_type, ID>(),
format_str);
} else if constexpr (str[POS + 1] == ':') {
using type = get_type<ID, Args>;
constexpr auto result = parse_specs<type>(str, POS + 2, ID);
using id_type = get_type<ID, Args>;
constexpr auto result = parse_specs<id_type>(str, POS + 2, ID);
return parse_tail<Args, result.end, result.next_arg_id>(
spec_field<char_type, type, ID>{result.fmt}, format_str);
spec_field<char_type, id_type, ID>{result.fmt}, format_str);
} else {
return unknown_format();
}
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ struct ostream_params {
ostream_params() {}

template <typename... T>
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 <typename... T>
Expand Down
4 changes: 2 additions & 2 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
}

Expand Down
14 changes: 7 additions & 7 deletions test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ template <typename T> struct mock_buffer final : buffer<T> {

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;
}));
Expand Down Expand Up @@ -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*) {}
};

Expand Down Expand Up @@ -688,9 +688,9 @@ TYPED_TEST(IsStringTest, IsString) {
EXPECT_TRUE(fmt::detail::is_string<fmt::basic_string_view<TypeParam>>::value);
EXPECT_TRUE(
fmt::detail::is_string<derived_from_string_view<TypeParam>>::value);
using string_view = fmt::detail::std_string_view<TypeParam>;
EXPECT_TRUE(std::is_empty<string_view>::value !=
fmt::detail::is_string<string_view>::value);
using fmt_string_view = fmt::detail::std_string_view<TypeParam>;
EXPECT_TRUE(std::is_empty<fmt_string_view>::value !=
fmt::detail::is_string<fmt_string_view>::value);
EXPECT_TRUE(fmt::detail::is_string<my_ns::my_string<TypeParam>>::value);
EXPECT_FALSE(fmt::detail::is_string<my_ns::non_string>::value);
}
Expand Down
28 changes: 14 additions & 14 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ TEST(AllocatorTest, allocator_ref) {
check_forwarding(alloc, ref3);
}

typedef allocator_ref<std::allocator<char>> TestAllocator;
typedef allocator_ref<std::allocator<char>> std_allocator;

static void check_move_buffer(
const char* str, basic_memory_buffer<char, 5, TestAllocator>& buffer) {
const char* str, basic_memory_buffer<char, 5, std_allocator>& buffer) {
std::allocator<char>* alloc = buffer.get_allocator().get();
basic_memory_buffer<char, 5, TestAllocator> buffer2(std::move(buffer));
basic_memory_buffer<char, 5, std_allocator> 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()));
Expand All @@ -236,7 +236,7 @@ static void check_move_buffer(

TEST(MemoryBufferTest, MoveCtorInlineBuffer) {
std::allocator<char> alloc;
basic_memory_buffer<char, 5, TestAllocator> buffer((TestAllocator(&alloc)));
basic_memory_buffer<char, 5, std_allocator> buffer((std_allocator(&alloc)));
const char test[] = "test";
buffer.append(string_view(test, 4));
check_move_buffer("test", buffer);
Expand All @@ -248,14 +248,14 @@ TEST(MemoryBufferTest, MoveCtorInlineBuffer) {

TEST(MemoryBufferTest, MoveCtorDynamicBuffer) {
std::allocator<char> alloc;
basic_memory_buffer<char, 4, TestAllocator> buffer((TestAllocator(&alloc)));
basic_memory_buffer<char, 4, std_allocator> 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<char, 4, TestAllocator> buffer2(std::move(buffer));
basic_memory_buffer<char, 4, std_allocator> 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()));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<char> width_ref;
Expand All @@ -2111,15 +2111,15 @@ 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),
precision(other.precision),
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; }
Expand Down Expand Up @@ -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, "");
Expand Down Expand Up @@ -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, "");
Expand Down
12 changes: 5 additions & 7 deletions test/locale-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,13 @@ template <class charT> struct formatter<std::complex<double>, charT> {
FormatContext& ctx) {
detail::handle_dynamic_spec<detail::precision_checker>(
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<std::locale>(),
"{:" + format_specs + "}", c.real());
"{:" + specs + "}", c.real());
auto imag = fmt::format(ctx.locale().template get<std::locale>(),
"{:" + format_specs + "}", c.imag());
"{:" + specs + "}", c.imag());
auto fill_align_width = std::string();
if (specs_.width > 0)
fill_align_width = fmt::format(">{}", specs_.width);
Expand Down
5 changes: 3 additions & 2 deletions test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {

struct test_buffer final : fmt::detail::buffer<char> {
explicit test_buffer(size_t size)
: fmt::detail::buffer<char>(nullptr, size, size) {}
: fmt::detail::buffer<char>(nullptr, size, size) {}
void grow(size_t) {}
} buffer(max_size);

Expand All @@ -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;
Expand Down