Skip to content

Fix #14520: false positive: passedByValue on declaration with const#8460

Open
ludviggunne wants to merge 4 commits intodanmar:mainfrom
ludviggunne:14520
Open

Fix #14520: false positive: passedByValue on declaration with const#8460
ludviggunne wants to merge 4 commits intodanmar:mainfrom
ludviggunne:14520

Conversation

@ludviggunne
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/checkother.cpp Outdated
Comment thread lib/checkother.cpp Outdated
Comment thread test/testother.cpp
Comment on lines -2912 to 2913
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());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks I see

Comment thread test/testother.cpp
Co-authored-by: Oliver Stöneberg <firewave@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants