diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 2a9cf1a71..c322ee565 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -427,19 +427,25 @@ static void compileTerm(Token *& tok, std::stack &op) } else if (tok->str() == "return") { compileUnaryOp(tok, compileExpression, op); } else if (tok->isName()) { + const bool templatefunc = Token::Match(tok, "%var% <") && Token::simpleMatch(tok->linkAt(1), "> ("); if (Token::Match(tok->next(), "++|--")) { // post increment / decrement tok = tok->next(); tok->astOperand1(tok->previous()); op.push(tok); tok = tok->next(); - } else if (!Token::Match(tok->next(), "(|[")) { + } else if (tok->next() && tok->next()->str() == "<" && tok->next()->link() && !templatefunc) { + op.push(tok); + tok = tok->next()->link()->next(); + compileTerm(tok,op); + } else if (!Token::Match(tok->next(), "(|[") && !templatefunc) { op.push(tok); tok = tok->next(); } else { Token *name = tok; - tok = tok->tokAt(2); + Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next(); + tok = par->next(); if (Token::Match(tok, ")|]")) { - name->next()->astOperand1(name); + par->astOperand1(name); tok = tok->next(); } else { Token *prev = name; @@ -458,7 +464,7 @@ static void compileTerm(Token *& tok, std::stack &op) tok = tok->next(); } } - op.push(name->next()); + op.push(par); } } else if (Token::Match(tok, "++|--")) { bool pre = false; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 26de7941d..33e19fdca 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -10037,6 +10037,8 @@ private: else if (!links.empty() && Token::Match(tok,")|]")) { Token::createMutualLinks(links.top(), tok); links.pop(); + } else if (Token::Match(tok, "< %type% >")) { + Token::createMutualLinks(tok, tok->tokAt(2)); } } @@ -10130,7 +10132,8 @@ private: } void asttemplate() const { // uninstantiated templates will have <,>,etc.. - ASSERT_EQUALS("aint<>3==", testAst("a()==3")); + ASSERT_EQUALS("a(3==", testAst("a()==3")); + ASSERT_EQUALS("ab(==", testAst("a == b(); f();")); } };