-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Revert recent changes in checkConstVariable(), add tests (refs #12203) #5696
Conversation
@@ -3371,6 +3374,15 @@ class TestOther : public TestFixture { | |||
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 's1' can be declared as reference to const\n" | |||
"[test.cpp:1]: (style) Parameter 's2' can be declared as reference to const\n", | |||
errout.str()); | |||
|
|||
check("struct S {\n" | |||
" void f(int& r) { p = &r; }\n" |
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.
I think isVariableChanged
can be updated to handle this case. We are already doing something similiar for references.
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.
I would not even expect isVariableChanged()
to return true
here.
" 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" |
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 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).
No description provided.