Open
Conversation
shaiku
reviewed
Jul 28, 2023
| stream << name_stream.str(); | ||
| std::string_view help_view(argument.m_help); | ||
| while ((pos = argument.m_help.find('\n', prev)) != std::string::npos) { | ||
| while ((pos = argument.m_help.find('\n', prev)) != (signed)std::string::npos) { |
There was a problem hiding this comment.
Instead of c-style casting npos to signed I would change auto pos = 0 to size_t pos = 0. The root problem is that "pos" is being auto-typed to an int whereas the return type of string::find() and the type of string::npos are both size_t.
There was a problem hiding this comment.
It also gets auto-typed correctly if you mark the zeros as unsigned:
auto pos = 0u;
auto prev = 0u;There was a problem hiding this comment.
I resolved/suppressed the warning by using a static_cast, my minimal reasoning was that the std::string::npos will always be a signed int (of -1) according to the std::string::npos https://cplusplus.com/reference/string/string/npos/
while ((pos = argument.m_help.find('\n', prev)) != static_cast<int>(std::string::npos)) {
|
亲,来信已经收到!祝你快乐!
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before:
./libs/argparse/include/argparse/argparse.hpp: In function ‘std::ostream& argparse::operator<<(std::ostream&, const argparse::Argument&)’:
./libs/argparse/include/argparse/argparse.hpp:686:53: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
686 | while ((pos = argument.m_help.find('\n', prev)) != std::string::npos) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
After:
Build OK