Visitar URL original
Partial fix for #13330 FN knownConditionTrueFalse with comma operator by chrchr-github · Pull Request #8965 · cppcheck-opensource/cppcheck · GitHub
Skip to content

Partial fix for #13330 FN knownConditionTrueFalse with comma operator - #8965

Open
chrchr-github wants to merge 5 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_13330
Open

chrchr-github wants to merge 5 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_13330

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck

Copy link
Copy Markdown

Test results for commit 2f62d59 (tools/test-my-pr.py, main compared to this PR):

Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8965/
packages: 1000
Differing warnings: 6 (+6 -0)
AI review: 2 improvement, 4 regression (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8965/2026-10-26_14-53-58-2f62d59bd3d5-review.txt)
Timing: -0.4% (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8965/2026-10-26_14-53-58-2f62d59bd3d5_timing.html)

Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

The regressions stem from a single package, which uses this macro:

#define ERROR_EXIT(err)		  \
do				  \
{				  \
errcode = err;		  \
if (/*CONSTCOND*/(void)1,1)	  \
      	goto error_exit;	  \
}				  \
while (/*CONSTCOND*/(void)0,0)

I see no reason for that void cast/comma operator. A code search shows many instances of CONSTCOND, but I didn't find any including the cast.
https://codesearch.debian.net/search?q=CONSTCOND

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review

I found no new problems. With if, else if, while, for and switch, the comma in the condition now gets a value in the cases the PR targets. Real function calls, constructor calls, template calls and lambda calls are still not given the comma value. I found no new false positives in loops, in do/while, or where the variable is changed through a pointer argument or a global inside the condition. As the title says, this is a partial fix. if (g(), n) where g is not pure and has no visible body is still not reported. The six differences in the 1000-package run all come from the (void)1,1 / (void)0,0 macro, which the author has already explained in comments.md.

Testing

  • Built cppcheck and testrunner in pr/ and cppcheck in base/. All builds succeeded.
  • ./testrunner TestCondition TestValueFlow passed. The full ./testrunner -q also passed: 5362 tests, 0 failures.
  • I wrote scratch files and ran the PR binary on them, comparing with base where it mattered:
    • Newly reported with h() declared __attribute__((pure)), all correct:
      • if (h(), n), while (h(), n), else if (h(), n) and (h(), n) ? 1 : 2 give knownConditionTrueFalse.
      • if (n == 0) { if (h(), n == 0) {} } gives knownConditionTrueFalse.
      • switch (h(), n) { case 1: } gives unreachableSwitchCase.
      • if ((void)0, n) gives knownConditionTrueFalse.
    • Possible false positives, none reported:
      • while (h(), n < 10) { n++; }
      • do { n = k(0); } while (h(), n);
      • for (; h(), n < 3; n++)
      • if (h(), k(&n), n)
      • if (n = k(0), n)
      • x = 0; if (g(), x) where g sets the global x
    • Calls that should not get the comma value, unchanged from base:
      • S s(h(), n)
      • l(h(), n) where l is a lambda
      • t(h(), n) where t is a template
      • decltype(h(), n)(1) and sizeof(h(), n)
    • Still a false negative: if (h(), n) where h is a plain declaration with no body. This is the remaining part of #13330, as the "partial fix" title says.

Automated review of 2f62d59 by Claude. The pull request was built and tested locally.

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.

2 participants