From 32455e84411f8661975b8982591a76a20d2dc892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 26 Dec 2015 15:20:17 +0100 Subject: [PATCH] Fixed #7214 (ValueType: does not handle static_cast) --- lib/checkother.h | 2 +- lib/symboldatabase.cpp | 8 +++++++- test/testsymboldatabase.cpp | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkother.h b/lib/checkother.h index cf326c7e0..2a68cad5a 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -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(); } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b9ea1d502..e3d9885f8 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d04f74c3b..6efaf3d1b 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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(32);", "(")); // const.. ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\""));