Skip to content

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

Merged
vitaut merged 2 commits into
fmtlib:masterfrom
jgopel:enable-wshadow
Nov 3, 2020
Merged

vitaut merged 2 commits into
fmtlib:masterfrom
jgopel:enable-wshadow

Conversation

@jgopel

@jgopel jgopel commented Oct 28, 2020

Copy link
Copy Markdown
Contributor

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good but please fix CI build failures and address inline comments.

Comment thread include/fmt/os.h Outdated
ostream_params(T... params, int oflag) : ostream_params(params...) {
this->oflag = oflag;
ostream_params(T... params, int new_oflag) : ostream_params(params...) {
this->oflag = new_oflag;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this->.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread test/core-test.cc Outdated
template <typename ParseContext>
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
auto parse(ParseContext& parse_ctx) -> decltype(parse_ctx.begin()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep argument names as is but rename the data member to parse_ctx since it has wider scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - I'm glad you looked at that one, I had a feeling that the situation might be something like this but I didn't want to be too aggressive so I tried my best to keep the scope very local.

Comment thread test/format-test.cc Outdated
}

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow the naming conventions while at it:

using std_allocator = allocator_ref<std::allocator<char>>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Done

@jgopel
jgopel force-pushed the enable-wshadow branch 4 times, most recently from 187b3b0 to 9cc2342 Compare October 31, 2020 09:50
@jgopel
jgopel marked this pull request as draft October 31, 2020 10:03
@vitaut

vitaut commented Oct 31, 2020

Copy link
Copy Markdown
Contributor

A few more build failures: https://travis-ci.org/github/fmtlib/fmt/jobs/740386845

@jgopel

jgopel commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

I can't get this last set of errors to reproduce locally for reasons that are not clear to me, so there might be a bit of churn with using CI to find the errors.

@jgopel
jgopel force-pushed the enable-wshadow branch 2 times, most recently from 51fbcd4 to 40dab6e Compare November 2, 2020 20:47
@jgopel
jgopel marked this pull request as ready for review November 2, 2020 22:55
@jgopel

jgopel commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

Just in case anyone else encounters the issue of not being able to reproduce errors locally - the C++ standard seems to matter to at least GCC for whether or not -Wshadow generates warnings in certain narrow contexts.

Comment thread test/format-test.cc Outdated
auto s = fmt::detail::bit_cast<uint32_pair>(uint64_t{42});
EXPECT_EQ(fmt::detail::bit_cast<uint64_t>(s), 42ull);
s = fmt::detail::bit_cast<uint32_pair>(uint64_t(~0ull));
s = fmt::detail::bit_cast<uint32_pair>(~0ull);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated and technically not correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry about that - fixed.

Comment thread test/std-format-test.cc Outdated

// Parses a width argument id in the format { <digit> }.
constexpr auto parse(format_parse_context& ctx) {
auto parse(format_parse_context& ctx) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry about that - fixed

Problem:
- All `-Wshadow` warnings are fixed but there is nothing stopping them
  from being reintroduced.

Solution:
- Fail pedantic builds on `-Wshadow` warnings. This allows CI to prevent
  reoccurrence of the warning.

Notes:
- Not enabling `-Wshadow` for gcc versions 4 or lower because the
  warning is much more aggressive there to the point that it's mostly
  just noise.
@darklukee

Copy link
Copy Markdown
Contributor

@jgopel thank you for doing this. It was annoying my team for some time now :)

@vitaut
vitaut merged commit eb52ac7 into fmtlib:master Nov 3, 2020
@vitaut

vitaut commented Nov 3, 2020

Copy link
Copy Markdown
Contributor

Merged, thanks!

@jgopel
jgopel deleted the enable-wshadow branch November 7, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants