Repository navigation
Partial fix for #13330 FN knownConditionTrueFalse with comma operator - #8965
chrchr-github wants to merge 5 commits into
Conversation
|
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/ 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. |
|
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 |
dmcppcheck
left a comment
There was a problem hiding this comment.
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
cppcheckandtestrunnerin pr/ andcppcheckin base/. All builds succeeded. ./testrunner TestCondition TestValueFlowpassed. The full./testrunner -qalso 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 : 2give 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)wheregsets the globalx
- Calls that should not get the comma value, unchanged from base:
S s(h(), n)l(h(), n)wherelis a lambdat(h(), n)wheretis a templatedecltype(h(), n)(1)andsizeof(h(), n)
- Still a false negative:
if (h(), n)wherehis a plain declaration with no body. This is the remaining part of #13330, as the "partial fix" title says.
- Newly reported with
Automated review of 2f62d59 by Claude. The pull request was built and tested locally.
No description provided.