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

Conversation

jgopel
Copy link
Contributor

@jgopel jgopel commented Oct 28, 2020

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

Copy link
Contributor

@vitaut vitaut left a comment

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.

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
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
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -213,12 +213,12 @@ struct custom_context {

template <typename T> struct formatter_type {
template <typename ParseContext>
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
auto parse(ParseContext& parse_ctx) -> decltype(parse_ctx.begin()) {
Copy link
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
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.

@@ -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>> StdAllocator;
Copy link
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
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
Copy link
Contributor

vitaut commented Oct 31, 2020

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

@jgopel
Copy link
Contributor Author

jgopel commented Nov 2, 2020

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
Copy link
Contributor Author

jgopel commented Nov 2, 2020

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.

s = fmt::detail::bit_cast<uint32_pair>(uint64_t(~0ull));
s = fmt::detail::bit_cast<uint32_pair>(~0ull);
Copy link
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
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.

constexpr auto parse(format_parse_context& ctx) {
auto parse(format_parse_context& ctx) {
Copy link
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
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
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
Copy link
Contributor

vitaut commented Nov 3, 2020

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