Revert recent changes in checkConstVariable(), add tests (refs #12203)#5696
Merged
chrchr-github merged 6 commits intocppcheck-opensource:mainfrom Nov 22, 2023
Merged
Conversation
pfultz2
reviewed
Nov 22, 2023
| errout.str()); | ||
|
|
||
| check("struct S {\n" | ||
| " void f(int& r) { p = &r; }\n" |
Contributor
There was a problem hiding this comment.
I think isVariableChanged can be updated to handle this case. We are already doing something similiar for references.
Collaborator
Author
There was a problem hiding this comment.
I would not even expect isVariableChanged() to return true here.
pfultz2
reviewed
Nov 22, 2023
| " int* p;\n" | ||
| "};\n" | ||
| "void g(std::vector<int>& v1, std::vector<int*>& v2) {\n" | ||
| " std::transform(v1.begin(), v1.end(), v2.begin(), [](auto& x) { return &x; });\n" |
Contributor
There was a problem hiding this comment.
This can't be handled by isVariableChanged. We need to check if it escapes. Ideally it would be nice to write a generic function(maybe escapes or referenceEscapes?) to check for this(with an indirect parameter for pointers and references), this should help to simplify the logic for this checker(and maybe others).
pfultz2
approved these changes
Nov 22, 2023
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.
No description provided.