Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,8 @@ void CheckConditionImpl::alwaysTrueFalse()
continue;
if (Token::simpleMatch(condition, "return") && Token::Match(tok, "%assign%"))
continue;
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%"))
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%") &&
!(tok->hasKnownValue(ValueFlow::Value::ValueType::SYMBOLIC) && tok->getKnownValue(ValueFlow::Value::ValueType::SYMBOLIC)->tokvalue->str() == "("))
continue;
bool warnForNumber = false;
if (Token::Match(tok, "%num%|%bool%|%char%")) {
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ bool SymbolDatabase::isRecordTypeWithoutSideEffects(const Type* type) const
for (const Variable& var : type->classScope->varlist) {
withoutSideEffects = isVariableWithoutSideEffects(var, type);
if (!withoutSideEffects) {
return withoutSideEffects;
return false;
}
}
return (withoutSideEffects = true);
Expand Down
2 changes: 1 addition & 1 deletion test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4878,7 +4878,7 @@ class TestCondition : public TestFixture {
" }\n"
" 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.


check("static bool parse(int r) {\n" // #15031
" bool res = false;\n"
Expand Down
Loading