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
1 change: 1 addition & 0 deletions .selfcheck_suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h
functionStatic:externals/tinyxml2/tinyxml2.cpp
funcArgNamesDifferent:externals/tinyxml2/tinyxml2.cpp
nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp
knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp
useStlAlgorithm:externals/simplecpp/simplecpp.cpp
missingMemberCopy:externals/simplecpp/simplecpp.h
2 changes: 2 additions & 0 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,8 @@ void CheckCondition::alwaysTrueFalse()
condition = parent->astParent()->astParent()->previous();
else if (Token::Match(tok, "%comp%"))
condition = tok;
else if (tok->str() == "(" && astIsBool(parent) && Token::Match(parent, "%assign%"))
condition = tok;
else
continue;
}
Expand Down
13 changes: 13 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4787,6 +4787,19 @@ class TestCondition : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("struct S {\n" // #14392
" bool g() const { return m; }\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure it doesnt warn when doing bool g() const { return true; }.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, this is a different warning.

" bool m{};\n"
"};\n"
"void f(S s) {\n"
" if (s.g()) {\n"
" bool b = s.g();\n"
" return b;\n"
" }\n"
" return false;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:21]: (style) Condition 's.g()' is always true [knownConditionTrueFalse]\n", errout_str());
Copy link
Owner

Choose a reason for hiding this comment

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

It seems unfortunate to say that "Condition" is always true. The RHS in a assignment is not a "Condition".

Copy link
Owner

Choose a reason for hiding this comment

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

what happens if g() returns an int instead? That is not "true" or "false".

}

void alwaysTrueSymbolic()
Expand Down
Loading