-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14520: false positive: passedByValue on declaration with const #8460
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 3 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 |
|---|---|---|
|
|
@@ -2909,7 +2909,7 @@ class TestOther : public TestFixture { | |
| check("struct X { int a[5]; }; extern \"C\" void f(X v) { }"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("struct X { int a[5]; }; void f(const X v);"); | ||
| check("struct X { int a[5]; }; void f(const X v) { (void) v; }"); | ||
| ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); | ||
|
Comment on lines
-2912
to
2916
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. Shouldn't we keep the existing test (in addition to the changed one) as that is the false positive fixed here.
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. I believe the intention of this test is to ensure we warn for struct parameters, so I wanted to keep that meaning. Although, now that you point it out there is a false positive here, but I think it's unrelated to the ticket (there is an implementation).
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. There is a misunderstanding. The test in its original form without the implementation showed the false positive. That is the fix that we no longer warn for it. Instead of just adding the implementation so the result stays the same we should have tests with and without implementation.
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. I think I'm still misunderstanding... after this patch this test would have to be updated either way (result/input code). 0357bb6 introduces a test without implementation, whereas this now has an implementation. Are you suggesting two new tests that are identical except for present/missing implementation?
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. The new test uses the exact case from the ticket which involves a class and the constructor. The test in question here is about free-standing functions which would be missing.
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. Ah, thanks I see |
||
|
|
||
| check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }"); | ||
|
|
@@ -4108,6 +4108,14 @@ class TestOther : public TestFixture { | |
| " if (*pp) {}\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("class C {\n" | ||
| "public:\n" | ||
| " explicit C(const std::string s);\n" | ||
| "private:\n" | ||
| " std::string _s;\n" | ||
| "};\n"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
| } | ||
|
|
||
| void constParameterCallback() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.