Repository navigation
Fix #15116 FP stlFindInsert (modifying existing element) #8968
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -7424,6 +7424,17 @@ class TestStl : public TestFixture { | |
| dinit(CheckOptions, $.inconclusive = true)); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("void f(std::map<int, bool>& m) {\n" // #15116 | ||
| " if (m.count(1) != 0)\n" | ||
| " m[1] = true;\n" | ||
| "}\n" | ||
| "void g(std::map<int, bool>& m) {\n" | ||
| " if (m.count(1) == 1)\n" | ||
| " m[1] = true;\n" | ||
| "}\n", | ||
| dinit(CheckOptions, $.inconclusive = true)); | ||
| ASSERT_EQUALS("", errout_str()); // TODO: warn about duplicate search | ||
|
Collaborator
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. Why are we removing the warning here? We should just update the warning message.
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. Feel free to add the logic necessary to generate a fitting error message in this case. The condition handling also needs tweaking, see https://trac.cppcheck.net/ticket/15146
Collaborator
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 update the logic for the error message in #8975. |
||
|
|
||
| // #9218 - not small type => do not warn if cpp standard is < c++17 | ||
| { | ||
| Settings s = settings; | ||
|
|
||
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.
AI review
Requiring
==is too narrow forcount(), because the operator alone does not say whether the condition means "key absent".if (s.count(x) != 1) s.insert(x);on astd::set, andif (m.count(x) < 1) m[x] = 1;, both mean "absent". Base reportedstlFindInsertfor both, and with this PR neither warns: lost true positives.The fix should check the meaning of the comparison: absent means
== 0,!= 1(for a set),< 1or<= 0. It should not filter on==only. A test for one of these cases would help too.