-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Revert recent changes in checkConstVariable(), add tests (refs #12203) #5696
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
b2eb818
040952e
b35ed6e
94280c9
a62ab03
7dc0511
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,31 +2794,34 @@ class TestOther : public TestFixture { | |
| "void a(T& x) {\n" | ||
| " x.dostuff();\n" | ||
| " const U * y = dynamic_cast<const U *>(&x);\n" | ||
| " y->mutate();\n" // to avoid warnings that y can be const | ||
| "}"); | ||
| ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout.str()); | ||
| TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it | ||
| check("struct T : public U { void dostuff() const {}};\n" | ||
| "void a(T& x) {\n" | ||
| " x.dostuff();\n" | ||
| " U const * y = dynamic_cast<U const *>(&x);\n" | ||
| " y->mutate();\n" // to avoid warnings that y can be const | ||
| "}"); | ||
| ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout.str()); | ||
| TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it | ||
| check("struct T : public U { void dostuff() const {}};\n" | ||
| "void a(T& x) {\n" | ||
| " x.dostuff();\n" | ||
| " U * const y = dynamic_cast<U * const>(&x);\n" | ||
| " const U const * const * const * const y = dynamic_cast<const U const * const * const * const>(&x);\n" | ||
| " y->mutate();\n" // to avoid warnings that y can be const | ||
| "}"); | ||
| ASSERT_EQUALS("", errout.str()); | ||
| check("struct T : public U { void dostuff() const {}};\n" | ||
| "void a(T& x) {\n" | ||
| " x.dostuff();\n" | ||
| " U const * const * * const y = dynamic_cast<U const * const * * const>(&x);\n" | ||
| " const U const * const * const * const y = dynamic_cast<const U const * const * const * const>(&x);\n" | ||
| " y->mutate();\n" // to avoid warnings that y can be const | ||
| "}"); | ||
| ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as reference to const\n", errout.str()); | ||
| TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it | ||
| check("struct T : public U { void dostuff() const {}};\n" | ||
| "void a(T& x) {\n" | ||
| " x.dostuff();\n" | ||
| " my::fancy<typename type const *> const * * const y = dynamic_cast<my::fancy<typename type const *> const * * const>(&x);\n" | ||
| " const U const * const * * const y = dynamic_cast<const U const * const * * const>(&x);\n" | ||
| " y->mutate();\n" // to avoid warnings that y can be const | ||
| "}"); | ||
| ASSERT_EQUALS("", errout.str()); | ||
|
|
@@ -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" | ||
| " 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can't be handled by |
||
| "}\n"); | ||
| ASSERT_EQUALS("", errout.str()); | ||
| } | ||
|
|
||
| void constParameterCallback() { | ||
|
|
@@ -3760,7 +3772,7 @@ class TestOther : public TestFixture { | |
| check("void f(int& i) {\n" | ||
| " new (&i) int();\n" | ||
| "}\n"); | ||
| TODO_ASSERT_EQUALS("", "[test.cpp:1]: (style) Parameter 'i' can be declared as reference to const\n", errout.str()); // don't crash | ||
| ASSERT_EQUALS("", errout.str()); // don't crash | ||
|
|
||
| check("void f(int& i) {\n" | ||
| " int& r = i;\n" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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
isVariableChangedcan 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 returntruehere.