-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix FP useStlAlgorithm (don't suggest std::accumulate when nothing is accumulated) #4647
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
Changes from all commits
ded037f
b687633
fa13c04
368fa80
ffaff0a
b73aeb6
78dd2ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5200,6 +5200,25 @@ class TestStl : public TestFixture { | |
| "}\n", | ||
| true); | ||
| ASSERT_EQUALS("", errout.str()); | ||
|
|
||
| check("bool g(int);\n" | ||
| "int f(const std::vector<int>& v) {\n" | ||
| " int ret = 0;\n" | ||
| " for (const auto i : v)\n" | ||
| " if (!g(i))\n" | ||
| " ret = 1;\n" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this still warn when doing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We suggest |
||
| " return ret;\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("", errout.str()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should suggest
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, since those algorithms short-circuit. Presumably
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then it should probably be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use |
||
|
|
||
| check("int f(const std::vector<int>& v) {\n" | ||
| " int ret = 0;\n" | ||
| " for (const auto i : v)\n" | ||
| " if (i < 5)\n" | ||
| " ret = 1;\n" | ||
| " return ret;\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::any_of, std::all_of, std::none_of algorithm instead of a raw loop.\n", errout.str()); | ||
| } | ||
|
|
||
| void loopAlgoMinMax() { | ||
|
|
||
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.
This should be moved up to the
ifabove, so it isif (accumulateBoolLiteral(assignTok, assignVarId) || assignTok->str() == "=")