Fix 11295: Regression FP: knownConditionTrueFalse (#4443)

This commit is contained in:
Paul Fultz II 2022-09-06 00:31:38 -05:00 committed by GitHub
parent 3d10e67b3d
commit 016793f258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1494,7 +1494,9 @@ void CheckCondition::alwaysTrueFalse()
continue;
if (!isUsedAsBool(tok))
continue;
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%|%assign%"))
if (Token::simpleMatch(condition, "return") && Token::Match(tok, "%assign%"))
continue;
if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%"))
continue;
if (Token::Match(tok, "%num%|%bool%|%char%"))
continue;

View File

@ -4341,6 +4341,13 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f()' is always true\n"
"[test.cpp:4]: (style) Condition 'f()==3' is always true\n",
errout.str());
check("int f() {\n"
" const char *n;\n"
" return((n=42) &&\n"
" *n == 'A');\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueSymbolic()