Skip to content

Commit 9797ce8

Browse files
committed
Fix #15031 (False positive: knownConditionTrueFalse reported when calling a function with a known result)
1 parent 9b3b160 commit 9797ce8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ void CheckConditionImpl::alwaysTrueFalse()
15561556
condition = parent->astParent()->astParent()->previous();
15571557
else if (Token::Match(tok, "%comp%"))
15581558
condition = tok;
1559-
else if ((tok->str() == "(" || (hasComp && Token::Match(tok, "!|%var%"))) && astIsBool(parent) && Token::Match(parent, "%assign%"))
1559+
else if (hasComp && Token::Match(tok, "!|%var%") && astIsBool(parent) && Token::Match(parent, "%assign%"))
15601560
condition = tok;
15611561
else
15621562
continue;

test/testcondition.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,7 +3668,7 @@ class TestCondition : public TestFixture {
36683668
"}\n");
36693669
ASSERT_EQUALS("", errout_str());
36703670

3671-
check("long X::g(bool unknown, int& result) {\n"
3671+
check("long g(bool unknown, int& result) {\n"
36723672
" long ret = 0;\n"
36733673
" bool f = false;\n"
36743674
" f = f || unknown;\n"
@@ -4878,7 +4878,18 @@ class TestCondition : public TestFixture {
48784878
" }\n"
48794879
" return false;\n"
48804880
"}\n");
4881-
ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:21]: (style) Assigned value 's.g()' is always true [knownConditionTrueFalse]\n", errout_str());
4881+
TODO_ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:21]: (style) Assigned value 's.g()' is always true [knownConditionTrueFalse]\n", "", errout_str());
4882+
4883+
check("static bool parse(int r) {\n" // #15031
4884+
" bool res = false;\n"
4885+
" return res;\n"
4886+
"}\n"
4887+
"\n"
4888+
"int main (void) {\n"
4889+
" bool res = parse(1101);\n"
4890+
" return res;\n"
4891+
"}\n");
4892+
ASSERT_EQUALS("", errout_str());
48824893

48834894
check("void f(const void* p) {\n" // #11519
48844895
" bool b = false;\n"

0 commit comments

Comments
 (0)