Fixed #7978 (ValueType: container type not set properly)

This commit is contained in:
Daniel Marjamäki 2017-04-06 07:07:20 +02:00
parent fee86b9684
commit fd2651909c
2 changed files with 19 additions and 15 deletions

View File

@ -4802,12 +4802,16 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
valuetype->sign = ValueType::Sign::UNSIGNED; valuetype->sign = ValueType::Sign::UNSIGNED;
if (type->str() == "const") if (type->str() == "const")
valuetype->constness |= (1 << (valuetype->pointer - pointer0)); valuetype->constness |= (1 << (valuetype->pointer - pointer0));
else if (Token::Match(type, "%name% :: %name%")) { else if (const Library::Container *container = settings->library.detectContainer(type)) {
const Library::Container *container = settings->library.detectContainer(type);
if (container) {
valuetype->type = ValueType::Type::CONTAINER; valuetype->type = ValueType::Type::CONTAINER;
valuetype->container = container; valuetype->container = container;
} else { while (Token::Match(type, "%name%|::|<")) {
if (type->str() == "<" && type->link())
type = type->link();
type = type->next();
}
continue;
} else if (Token::Match(type, "%name% :: %name%")) {
std::string typestr; std::string typestr;
const Token *end = type; const Token *end = type;
while (Token::Match(end, "%name% :: %name%")) { while (Token::Match(end, "%name% :: %name%")) {
@ -4817,7 +4821,6 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
typestr += end->str(); typestr += end->str();
if (valuetype->fromLibraryType(typestr, settings)) if (valuetype->fromLibraryType(typestr, settings))
type = end; type = end;
}
} else if (ValueType::Type::UNKNOWN_TYPE != ValueType::typeFromString(type->str(), type->isLong())) } else if (ValueType::Type::UNKNOWN_TYPE != ValueType::typeFromString(type->str(), type->isLong()))
valuetype->type = ValueType::typeFromString(type->str(), type->isLong()); valuetype->type = ValueType::typeFromString(type->str(), type->isLong());
else if (type->str() == "auto") { else if (type->str() == "auto") {

View File

@ -4438,6 +4438,7 @@ private:
c.startPattern = "C"; c.startPattern = "C";
sC.library.containers["C"] = c; sC.library.containers["C"] = c;
ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC)); ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC));
ASSERT_EQUALS("container(C) *", typeOf("x=(C*)c;","(","test.cpp",&sC));
} }
// new // new