diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0aaf6944e..35621f4a1 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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 vtParents = getParentValueTypes(tok, settings); diff --git a/test/testother.cpp b/test/testother.cpp index 0615492fb..3997d333a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11640,6 +11640,12 @@ private: " if (dynamic_cast(b)) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("bool (*ptr)();\n" // #12170 + "void f() {\n" + " if (!ptr || !ptr()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };