Fixed #9131 (Tokenizer::createLinks2; using std::list; list<config_option*> stack;)

This commit is contained in:
Daniel Marjamäki 2019-05-14 20:30:02 +02:00
parent 4e94c64da8
commit 79bb22f038
2 changed files with 25 additions and 3 deletions

View File

@ -3792,6 +3792,7 @@ void Tokenizer::createLinks2()
const Token * templateToken = nullptr; const Token * templateToken = nullptr;
bool isStruct = false; bool isStruct = false;
std::set<std::string> usingNames;
std::map<std::string, bool> templateNames; std::map<std::string, bool> templateNames;
templateNames["template"] = true; templateNames["template"] = true;
@ -3802,6 +3803,14 @@ void Tokenizer::createLinks2()
else if (Token::Match(token, "[;{}]")) else if (Token::Match(token, "[;{}]"))
isStruct = false; isStruct = false;
if (Token::Match(token, "using %name% ::")) {
const Token *tok2 = token->tokAt(3);
while (Token::Match(tok2, "%name% ::"))
tok2 = tok2->tokAt(2);
if (Token::Match(tok2, "%name% ;"))
usingNames.insert(tok2->str());
}
if (token->link()) { if (token->link()) {
if (Token::Match(token, "{|[|(")) if (Token::Match(token, "{|[|("))
type.push(token); type.push(token);
@ -3851,7 +3860,11 @@ void Tokenizer::createLinks2()
while (!type.empty() && type.top()->str() == "<") while (!type.empty() && type.top()->str() == "<")
type.pop(); type.pop();
} else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) { } else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) {
if (!Token::simpleMatch(token->tokAt(-2), "::")) { const bool isScoped = Token::simpleMatch(token->tokAt(-2), "::") ||
(Token::Match(token->tokAt(-2), "; %name% <") && usingNames.count(token->previous()->str()));
const bool isTemplateDecl = isScoped || Token::Match(token->tokAt(-2), "%name% %name% <");
const bool isTemplateArgPointerType = Token::Match(token, "< %name%| %stype% * >");
if (!isTemplateDecl && !isTemplateArgPointerType) {
std::map<std::string, bool>::const_iterator it = templateNames.find(token->previous()->str()); std::map<std::string, bool>::const_iterator it = templateNames.find(token->previous()->str());
if (it == templateNames.end()) { if (it == templateNames.end()) {
const std::string &name = token->previous()->str(); const std::string &name = token->previous()->str();

View File

@ -4771,13 +4771,22 @@ private:
} }
{ {
// #9094 // #9094 - template usage or comparison?
const char code[] = "a = f(x%x<--a==x>x);"; const char code[] = "a = f(x%x<--a==x>x);";
Tokenizer tokenizer(&settings0, this); Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link()); ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link());
} }
{
// #9131 - template usage or comparison?
const char code[] = "using std::list; list<t *> l;";
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
}
} }
void simplifyString() { void simplifyString() {
@ -7337,7 +7346,7 @@ private:
const char code1[] = "using uno::Ref;\n" const char code1[] = "using uno::Ref;\n"
"Ref<X> r;\n" "Ref<X> r;\n"
"int x(0);"; "int x(0);";
ASSERT_EQUALS("unoRef:: RefX<r> x0(", testAst(code1)); ASSERT_EQUALS("unoRef:: x0(", testAst(code1));
} }
void astunaryop() { // unary operators void astunaryop() { // unary operators