Skip to content

Commit 016793f

Browse files
authored
Fix 11295: Regression FP: knownConditionTrueFalse (#4443)
1 parent 3d10e67 commit 016793f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkcondition.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,9 @@ void CheckCondition::alwaysTrueFalse()
14941494
continue;
14951495
if (!isUsedAsBool(tok))
14961496
continue;
1497-
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%|%assign%"))
1497+
if (Token::simpleMatch(condition, "return") && Token::Match(tok, "%assign%"))
1498+
continue;
1499+
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%"))
14981500
continue;
14991501
if (Token::Match(tok, "%num%|%bool%|%char%"))
15001502
continue;

test/testcondition.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,6 +4341,13 @@ class TestCondition : public TestFixture {
43414341
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f()' is always true\n"
43424342
"[test.cpp:4]: (style) Condition 'f()==3' is always true\n",
43434343
errout.str());
4344+
4345+
check("int f() {\n"
4346+
" const char *n;\n"
4347+
" return((n=42) &&\n"
4348+
" *n == 'A');\n"
4349+
"}\n");
4350+
ASSERT_EQUALS("", errout.str());
43444351
}
43454352

43464353
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)