-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Modernize integer comparison #4577
Conversation
e93a8a4
to
3e0b421
Compare
Thanks, this is the way we do it in the other parts of the library. The failing AppVeyor test was explicitly added to detect these problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the diff, it becomes obvious how frequent we use -1
as magic number for "unknown size". As it is mostly used in the context of the SAX interface, it could be a good idea to define a constant unknown_size
in that header and use this throughout the code.
Thank you for reviewing my PR. Edit: Sorry, I misunderstood your comment. I will make the changes as suggested by @gregmarr |
It's used in the parser, and in the main class in the
|
It depends. If by "first issue" you mean first in this repository, but you have significant experience in template metaprogramming and SFINAE, then maybe. If you mean a good issue for an inexperienced programmer, then no. The However, I think that using |
If this PR is sufficient to fix the Clang-Tidy warning |
reference set_parent(reference j, std::size_t old_capacity = static_cast<std::size_t>(-1)) to reference set_parent(reference j, std::size_t old_capacity = std::numeric_limits<std::size_t>::max())) with a respective comment about this value. Then we have the following appearances of
Interestingly, we also have in binary_reader: static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1); which is used at some places. While this comment should make the case for moving the value closer to the parser, I think I over-engineered this in my head. So I think having a |
2aae6c9
to
ec8e61e
Compare
Replace static_cast<size_t>(-1) with std::numeric_limits<std::size_t>::max() via the detail::unknown_size() function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thanks! |
Thank you for your thorough feedback. I look forward to collaborating on more "first good issue" changes! |
You could help by leaving a review at #4581. |
Replace static_cast<size_t>(-1) with std::numeric_limitsstd::size_t::max() as suggested in #4559
Builds are failing in MSVS because of
<Windows.h>
header file that includes macro definitions named max and min:one way to solve this issue is to wrap
max
with parenthesis.Source: https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax