Skip to content

Fix #15056 (knownconditiontruefalse: remove warnings for return result) - #8877

Open
danmar wants to merge 5 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15056
Open

danmar wants to merge 5 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15056

Conversation

@danmar

@danmar danmar commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@danmar danmar changed the title Fix #15056 (split up knownconditiontruefalse) Fix #15056 (knownconditiontruefalse: explain warnings for return result) Sep 20, 2026
@danmar

danmar commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

@chrchr-github I remove these warnings for return values unless an explanation can be written. I don't personally know why we warn about the return. A warning about a return doesn't mean that the return expression can be removed.

my guess is that somebody didn't understand the purpose of knownconditiontruefalse and thought it would apply to return values and then I somehow didn't question it in the initial reviews and after that it grew..

@danmar

danmar commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

In general I don't see it as a problem that a calculation has a known result. I think it makes sense to write calculations in clear text instead of writing magic numbers. That makes the code more explicit.

Comment thread test/testcondition.cpp
" return (c <= 'a' && c >= 'z');\n"
"}\n"); // TODO: use s?
ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\n", errout_str());
ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:2:25]: (style) Condition 'c>='z'' is always false [knownConditionTrueFalse]\n", errout_str());

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.

instead of knownConditionTrueFalse.. this test case reminds me more about the "mutually exclusive comparisons" checker

@danmar

danmar commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

If you are able to explain the warnings I would be interested in that.

@danmar danmar changed the title Fix #15056 (knownconditiontruefalse: explain warnings for return result) Fix #15056 (knownconditiontruefalse: explain/remove warnings for return result) Sep 20, 2026
@chrchr-github

Copy link
Copy Markdown
Collaborator

If you are able to explain the warnings I would be interested in that.

Here's an old ticket about inconsistent warnings for known function results: https://trac.cppcheck.net/ticket/10452
Since you intend to redesign the checker anyway, I don't think it makes sense to dig further for explanations...

@danmar

danmar commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator Author

Here's an old ticket about inconsistent warnings for known function results: https://trac.cppcheck.net/ticket/10452

thanks as I read it the intention with that was not to warn about the return. But for conditions that contains such function call - and that is fine for me.

@danmar danmar changed the title Fix #15056 (knownconditiontruefalse: explain/remove warnings for return result) Fix #15056 (knownconditiontruefalse: remove warnings for return result) Sep 20, 2026
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