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,22 +4802,25 @@ 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); valuetype->type = ValueType::Type::CONTAINER;
if (container) { valuetype->container = container;
valuetype->type = ValueType::Type::CONTAINER; while (Token::Match(type, "%name%|::|<")) {
valuetype->container = container; if (type->str() == "<" && type->link())
} else { type = type->link();
std::string typestr; type = type->next();
const Token *end = type;
while (Token::Match(end, "%name% :: %name%")) {
typestr += end->str() + "::";
end = end->tokAt(2);
}
typestr += end->str();
if (valuetype->fromLibraryType(typestr, settings))
type = end;
} }
continue;
} else if (Token::Match(type, "%name% :: %name%")) {
std::string typestr;
const Token *end = type;
while (Token::Match(end, "%name% :: %name%")) {
typestr += end->str() + "::";
end = end->tokAt(2);
}
typestr += end->str();
if (valuetype->fromLibraryType(typestr, settings))
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