Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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"
Comment thread
chrchr-github marked this conversation as resolved.
" 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());
Comment thread
danmar marked this conversation as resolved.
Outdated
}

void alwaysTrueSymbolic()
Expand Down
Loading