ValueType: Better handling of unsigned unknown types

This commit is contained in:
Daniel Marjamäki 2016-01-05 19:47:11 +01:00
parent 5b6c684905
commit 58e28cb00e
2 changed files with 4 additions and 1 deletions

View File

@ -3770,6 +3770,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
valuetype->type = type->isLong() ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE; valuetype->type = type->isLong() ? ValueType::Type::LONGDOUBLE : ValueType::Type::DOUBLE;
else if (type->str() == "struct") else if (type->str() == "struct")
valuetype->type = ValueType::Type::NONSTD; valuetype->type = ValueType::Type::NONSTD;
else if (type->isName() && valuetype->sign != ValueType::Sign::UNKNOWN_SIGN && valuetype->pointer == 0U)
return nullptr;
else if (type->str() == "*") else if (type->str() == "*")
valuetype->pointer++; valuetype->pointer++;
if (!type->originalName().empty()) if (!type->originalName().empty())

View File

@ -3084,7 +3084,7 @@ private:
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token * const tok = Token::findsimplematch(tokenizer.tokens(),str); const Token * const tok = Token::findsimplematch(tokenizer.tokens(),str);
return tok->valueType()->str(); return tok->valueType() ? tok->valueType()->str() : std::string();
} }
void valuetype() { void valuetype() {
@ -3167,6 +3167,7 @@ private:
ASSERT_EQUALS("long long", typeOf("a = (long long)32;", "(")); ASSERT_EQUALS("long long", typeOf("a = (long long)32;", "("));
ASSERT_EQUALS("long double", typeOf("a = (long double)32;", "(")); ASSERT_EQUALS("long double", typeOf("a = (long double)32;", "("));
ASSERT_EQUALS("char", typeOf("a = static_cast<char>(32);", "(")); ASSERT_EQUALS("char", typeOf("a = static_cast<char>(32);", "("));
ASSERT_EQUALS("", typeOf("a = (unsigned x)0;", "("));
// const.. // const..
ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\"")); ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\""));