Fixed #7214 (ValueType: does not handle static_cast)

This commit is contained in:
Daniel Marjamäki 2015-12-26 15:20:17 +01:00
parent 0886ef9c5f
commit 32455e8441
3 changed files with 9 additions and 2 deletions

View File

@ -68,6 +68,7 @@ public:
checkOther.checkCommaSeparatedReturn();
checkOther.checkRedundantPointerOp();
checkOther.checkZeroDivision();
checkOther.checkNegativeBitwiseShift();
checkOther.checkInterlockedDecrement();
checkOther.checkUnusedLabel();
checkOther.checkEvaluationOrder();
@ -92,7 +93,6 @@ public:
checkOther.checkInvalidFree();
checkOther.checkRedundantCopy();
checkOther.checkNegativeBitwiseShift();
checkOther.checkSuspiciousEqualityComparison();
checkOther.checkComparisonFunctionIsAlwaysTrueOrFalse();
}

View File

@ -3782,7 +3782,6 @@ static void setValueType(Token *tok, const ValueType &valuetype)
setValueType(parent, vt);
return;
}
}
@ -3871,6 +3870,13 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens)
::setValueType(tok, valuetype);
}
// C++ cast
if (tok->astOperand2() && Token::Match(tok->astOperand1(), "static_cast|const_cast|dynamic_cast|reinterpret_cast < %name%") && tok->astOperand1()->linkAt(1)) {
ValueType valuetype;
if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype), ">"))
::setValueType(tok, valuetype);
}
// function
else if (tok->previous() && tok->previous()->function() && tok->previous()->function()->retDef) {
ValueType valuetype;

View File

@ -3070,6 +3070,7 @@ private:
ASSERT_EQUALS("long", typeOf("a = (long int)32;", "("));
ASSERT_EQUALS("long long", typeOf("a = (long long)32;", "("));
ASSERT_EQUALS("long double", typeOf("a = (long double)32;", "("));
ASSERT_EQUALS("char", typeOf("a = static_cast<char>(32);", "("));
// const..
ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\""));