Skip to content

Conversation

@aryanrahar
Copy link

@aryanrahar aryanrahar commented Aug 16, 2025

Adds a negative test next to existing checkCommaSeparatedReturn coverage:

  • plain return with no comma operator → expect no diagnostic

Placement: test/testother.cpp, registered in TestOther::run() after checkCommaSeparatedReturn.
Formatting: applied with .uncrustify.cfg.

Earlier version accidentally triggered constStatement; this version avoids unrelated warnings.
All tests pass locally.

…ntainers

Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
…a in return) [#13869]

Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
test/teststl.cpp Outdated

TEST_CASE(checkKnownEmptyContainer);
TEST_CASE(checkMutexes);
TEST_CASE(commaSeparatedReturn_no_fp);
Copy link
Owner

Choose a reason for hiding this comment

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

it seems misplaced where are our other commaSeparatedReturn tests?

my hope is that if we put related tests together it's possible to see overlaps and gaps ..

test/teststl.cpp Outdated
"}\n");
ASSERT_EQUALS("", errout_str());
}
void commaSeparatedReturn_no_fp()
Copy link
Owner

Choose a reason for hiding this comment

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

this code is not formatted properly. Either run the runformat script or there is a diff from the "format" action that you can download and apply.

Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
…se; no comma in return)

Signed-off-by: Aryan Rahar <aryanrahar1@gmail.com>
@aryanrahar
Copy link
Author

Moved the test to test/testother.cpp, registered it next to checkCommaSeparatedReturn, and formatted with .uncrustify.cfg.
Adjusted the case to a minimal plain return (no comma operator) to avoid unrelated diagnostics. ctest is green locally.

@sonarqubecloud
Copy link

@aryanrahar
Copy link
Author

is there any issue?

@chrchr-github
Copy link
Collaborator

https://trac.cppcheck.net/ticket/13869 says that the check is currently disabled anyway?

@firewave
Copy link
Collaborator

The point was rather to have test which trigger the warning although negative can be good as well. We mostly add them if false positives are encountered (sometimes already during development).

But as pointed out, this is a check which is disabled so it is rather pointless to add it.

@danmar
Copy link
Owner

danmar commented Aug 29, 2025

Thanks for the contribution but as the checker should be rewritten I think it does not make sense to add this test code.

Can you please look at rewriting the checker?

When the statement before the comma is redundant and can be removed without affecting the behavior let's warn.

this can be implemented relatively easily. if there is just some calculations and no function calls, assignments, increments nor decrements before the comma then warn.

@danmar
Copy link
Owner

danmar commented Aug 29, 2025

I close this PR.. please feel free to open a new PR that fixes https://trac.cppcheck.net/ticket/5076 by rewriting the checker..

@danmar danmar closed this Aug 29, 2025
@firewave
Copy link
Collaborator

Rewriting a checker seems too much of an ask for a first-time contributor (well, not even me would be able to rewrite it).

It would make more sense to look at the other tickets about missing test coverage for checks.

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.

4 participants