diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e56ca8a59..7bc450866 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3709,11 +3709,11 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype) valuetype->sign = ValueType::Sign::UNKNOWN_SIGN; valuetype->type = ValueType::Type::UNKNOWN_TYPE; while (Token::Match(type, "%name%|*|&") && !type->variable()) { - if (type->str() == "signed") + if (type->isSigned()) valuetype->sign = ValueType::Sign::SIGNED; - else if (type->str() == "unsigned") + else if (type->isUnsigned()) valuetype->sign = ValueType::Sign::UNSIGNED; - else if (type->str() == "bool") + if (type->str() == "bool") valuetype->type = ValueType::Type::BOOL; else if (type->str() == "char") valuetype->type = ValueType::Type::CHAR; @@ -3755,7 +3755,7 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens) ::setValueType(tok, ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U); else if (tok->str() == "(") { // cast - if (!tok->astOperand2() && !Token::Match(tok, "( %name%")) { + if (!tok->astOperand2() && Token::Match(tok, "( %name%")) { ValueType valuetype; if (Token::simpleMatch(parsedecl(tok->next(), &valuetype), ")")) ::setValueType(tok, valuetype.sign, valuetype.type, valuetype.pointer); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 29cd0eaa1..6ff2b1b44 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2969,12 +2969,17 @@ private: ASSERT_EQUALS("char", typeOf("*\"hello\"", "*")); // Variable calculations - ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+")); + ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+")); ASSERT_EQUALS("float", typeOf("float x; a = x + 1;", "+")); + ASSERT_EQUALS("signed int", typeOf("signed x; a = x + 1;", "x +")); + ASSERT_EQUALS("unsigned int", typeOf("unsigned x; a = x + 1;", "x +")); // array.. ASSERT_EQUALS("int*", typeOf("int x[10]; a = x + 1;", "+")); ASSERT_EQUALS("int", typeOf("int x[10]; a = x[0] + 1;", "+")); + + // cast.. + ASSERT_EQUALS("char", typeOf("a = (char)32;", "(")); } };