Fix #12170 FP knownPointerToBool with function pointer (#5646)

This commit is contained in:
chrchr-github 2023-11-12 10:20:18 +01:00 committed by GitHub
parent 212d2141d3
commit a6b7a8c1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1481,7 +1481,7 @@ bool isUsedAsBool(const Token* const tok, const Settings* settings)
return true;
if (isForLoopCondition(tok))
return true;
if (!Token::Match(parent, "%cop%")) {
if (!Token::Match(parent, "%cop%") && !(parent->str() == "(" && tok == parent->astOperand1())) {
if (parent->str() == "," && parent->isInitComma())
return false;
std::vector<ValueType> vtParents = getParentValueTypes(tok, settings);

View File

@ -11640,6 +11640,12 @@ private:
" if (dynamic_cast<D*>(b)) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("bool (*ptr)();\n" // #12170
"void f() {\n"
" if (!ptr || !ptr()) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};