Repository navigation
Fix #15203 FN constParameterPointer (push_back() of dereferenced pointer) #9016
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
13e6df3
63dda39
a007659
356445d
a3ddba5
dc123e5
d16a499
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 |
|---|---|---|
|
|
@@ -2794,7 +2794,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, | |
| const Token * ptok = tok2; | ||
| while (Token::Match(ptok->astParent(), ".|::")) | ||
| ptok = ptok->astParent(); | ||
| int pindirect = indirect; | ||
| int pindirect = std::max(indirect - derefs, 0); | ||
|
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. AI review With #include <vector>
#include <algorithm>
#include <iterator>
void f1(std::vector<int>* p) { std::fill(std::begin(*p), std::end(*p), 0); }
void f2(std::vector<int>* p) { *std::begin(*p) = 1; }
void f4(std::vector<int>* p) { std::sort(std::begin(*p), std::end(*p)); }The PR reports The reference version, |
||
| if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next())) | ||
| pindirect = 1; | ||
| bool inconclusive = false; | ||
|
|
||
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
direction="inout"makesstd::begin/std::rbegin(and the same change onstd::end/std::rend) count their argument as modified every time, even when the iterator is only read. As a result, the PR loses warnings that base reports:Base gives
constParameterReferencefor g1–g5 andconstVariableReferencefor g7. The PR gives none of these warnings. For a non-const argument,std::begin(x)behaves like the memberx.begin(). Whether it changes anything depends on how the returned iterator is used, as it does for.begin(). So the C9 false positive would be better fixed inisVariableChanged(): when the stripped dereference goes into a function with astart-iterator/end-iteratoryield, look at how the result is used. That would keep the library entry asin. Please also add a test that checks read-onlystd::begin(v)still givesconstParameterReference.