False positive dynamic_cast auto variable which has been checked against null (#2769)
This commit is contained in:
parent
dba7108832
commit
84dd0c961f
|
@ -488,7 +488,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
|||
|
||||
// cast..
|
||||
if (const Token *castType = getCastTypeStartToken(parent)) {
|
||||
if (astIsPointer(tok) && value.valueType == ValueFlow::Value::INT &&
|
||||
if (((tok->valueType() == nullptr && value.isImpossible()) || astIsPointer(tok)) && value.valueType == ValueFlow::Value::INT &&
|
||||
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
|
||||
return;
|
||||
const ValueType &valueType = ValueType::parseDecl(castType, settings);
|
||||
|
|
|
@ -3306,6 +3306,17 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int foo() {\n"
|
||||
" auto x = getX();\n"
|
||||
" if (x == nullptr)\n"
|
||||
" return 1;\n"
|
||||
" auto y = dynamic_cast<Y*>(x)\n"
|
||||
" if (y == nullptr)\n"
|
||||
" return 2;\n"
|
||||
" return 3;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// handleKnownValuesInLoop
|
||||
check("bool g();\n"
|
||||
"void f(bool x) {\n"
|
||||
|
|
Loading…
Reference in New Issue