Skip to content

Restore warning for #14392 - #8859

Open
chrchr-github wants to merge 2 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_14392_II
Open

chrchr-github wants to merge 2 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_14392_II

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread test/testcondition.cpp
" return false;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:21]: (style) Assigned value 's.g()' is always true [knownConditionTrueFalse]\n", "", errout_str());
ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:8:16]: (style) Return value 'b' is always true [knownConditionTrueFalse]\n", errout_str());

@danmar danmar Sep 17, 2026

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.

I am not sure. what is the motivation to warn here?

this checker is about known conditions from the start. I documented my understanding of this in man/checkers/knownConditionTrueFalse.md. If that motivation/description can be improved feel free to do it.

I feel that such return value warning should be a separate checker as you said here:
#8853 (comment)

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.

The motivation still comes from https://trac.cppcheck.net/ticket/14392
We warn for return s.g();, so we should also warn if the result is stored in an intermediate variable.

@danmar danmar Sep 19, 2026

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.

14392 does not contain a explanation.

I want to have an explanation for what the checker is looking for and why it warns.

The man/checkers/knownConditionTrueFalse.md I added has an explanation for when we warn for conditions that are always true and false that leads to redundant code. But it does not explain why we warn for return statements.. if the return statement is still needed I don't understand why we should warn and I have not got any explanation for that.

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