More robust Token::findClosingBracket

This commit is contained in:
Daniel Marjamäki 2020-11-30 19:26:15 +01:00
parent c846c0fbdc
commit 9aa69661b5
3 changed files with 11 additions and 2 deletions

View File

@ -861,6 +861,14 @@ const Token * Token::findClosingBracket() const
if (mStr != "<")
return nullptr;
if (!mPrevious)
return nullptr;
if (!(mPrevious->isName() ||
Token::Match(mPrevious->previous(), "operator %op% <") ||
Token::Match(mPrevious->tokAt(-2), "operator [([] [)]] <")))
return nullptr;
const Token *closing = nullptr;
const bool templateParameter(strAt(-1) == "template");
std::set<std::string> templateParameters;

View File

@ -5165,7 +5165,8 @@ void Tokenizer::removeExtraTemplateKeywords()
}
}
static std::string getExpression(const Token *tok) {
static std::string getExpression(const Token *tok)
{
std::string line;
for (const Token *prev = tok->previous(); prev && !Token::Match(prev, "[;{}]"); prev = prev->previous())
line = prev->str() + " " + line;

View File

@ -4798,7 +4798,7 @@ private:
std::istringstream istr(code);
tokenizer.createTokens(istr, "test.cpp");
tokenizer.createLinks();
tokenizer.splitTemplateRightAngleBrackets(false);
tokenizer.splitTemplateRightAngleBrackets(false);
const Token *_tok = tokenizer.tokens();
for (unsigned i = 0 ; i < offset ; ++i)