diff --git a/lib/token.cpp b/lib/token.cpp index dcf567e7d..9a1bbd04f 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -910,7 +910,7 @@ const Token * Token::findClosingBracket() const if (!mPrevious) return nullptr; - if (!(mPrevious->isName() || + if (!(mPrevious->isName() || Token::simpleMatch(mPrevious, "]") || Token::Match(mPrevious->previous(), "operator %op% <") || Token::Match(mPrevious->tokAt(-2), "operator [([] [)]] <"))) return nullptr; @@ -939,7 +939,7 @@ const Token * Token::findClosingBracket() const return nullptr; // we can make some guesses for template parameters else if (closing->str() == "<" && closing->previous() && - (closing->previous()->isName() || isOperator(closing->previous())) && + (closing->previous()->isName() || Token::simpleMatch(closing->previous(), "]") || isOperator(closing->previous())) && (templateParameter ? templateParameters.find(closing->strAt(-1)) == templateParameters.end() : true)) ++depth; else if (closing->str() == ">") { diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 64097d096..827f6f20c 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -106,6 +106,7 @@ private: TEST_CASE(canFindMatchingBracketsWithTooManyClosing); TEST_CASE(canFindMatchingBracketsWithTooManyOpening); TEST_CASE(findClosingBracket); + TEST_CASE(findClosingBracket2); TEST_CASE(expressionString); @@ -1084,6 +1085,13 @@ private: ASSERT(Token::simpleMatch(t, "> struct")); } + void findClosingBracket2() const { + givenACodeSampleToTokenize var("const auto g = []() {};\n"); // #11275 + + const Token* const t = Token::findsimplematch(var.tokens(), "<"); + ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">")); + } + void expressionString() const { givenACodeSampleToTokenize var1("void f() { *((unsigned long long *)x) = 0; }"); const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*");