parent
cbbf500cd4
commit
c6721688e2
|
@ -1467,7 +1467,7 @@ bool isUsedAsBool(const Token* const tok, const Settings* settings)
|
||||||
if (Token::Match(parent, "&&|!|%oror%"))
|
if (Token::Match(parent, "&&|!|%oror%"))
|
||||||
return true;
|
return true;
|
||||||
if (parent->isCast())
|
if (parent->isCast())
|
||||||
return isUsedAsBool(parent);
|
return !Token::simpleMatch(parent->astOperand1(), "dynamic_cast") && isUsedAsBool(parent);
|
||||||
if (parent->isUnaryOp("*"))
|
if (parent->isUnaryOp("*"))
|
||||||
return isUsedAsBool(parent);
|
return isUsedAsBool(parent);
|
||||||
if (Token::Match(parent, "==|!=") && (tok->astSibling()->isNumber() || tok->astSibling()->isKeyword()) && tok->astSibling()->hasKnownIntValue() &&
|
if (Token::Match(parent, "==|!=") && (tok->astSibling()->isNumber() || tok->astSibling()->isKeyword()) && tok->astSibling()->hasKnownIntValue() &&
|
||||||
|
|
|
@ -11460,6 +11460,15 @@ private:
|
||||||
" return A{x};\n"
|
" return A{x};\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Pointer expression 'x' converted to bool is always false.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pointer expression 'x' converted to bool is always false.\n", errout.str());
|
||||||
|
|
||||||
|
check("struct B { virtual void f() {} };\n" // #11929
|
||||||
|
"struct D : B {};\n"
|
||||||
|
"void g(B* b) {\n"
|
||||||
|
" if (!b)\n"
|
||||||
|
" return;\n"
|
||||||
|
" if (dynamic_cast<D*>(b)) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue