File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -910,7 +910,7 @@ const Token * Token::findClosingBracket() const
910910 if (!mPrevious )
911911 return nullptr ;
912912
913- if (!(mPrevious ->isName () ||
913+ if (!(mPrevious ->isName () || Token::simpleMatch ( mPrevious , " ] " ) ||
914914 Token::Match (mPrevious ->previous (), " operator %op% <" ) ||
915915 Token::Match (mPrevious ->tokAt (-2 ), " operator [([] [)]] <" )))
916916 return nullptr ;
@@ -939,7 +939,7 @@ const Token * Token::findClosingBracket() const
939939 return nullptr ;
940940 // we can make some guesses for template parameters
941941 else if (closing->str () == " <" && closing->previous () &&
942- (closing->previous ()->isName () || isOperator (closing->previous ())) &&
942+ (closing->previous ()->isName () || Token::simpleMatch (closing-> previous (), " ] " ) || isOperator (closing->previous ())) &&
943943 (templateParameter ? templateParameters.find (closing->strAt (-1 )) == templateParameters.end () : true ))
944944 ++depth;
945945 else if (closing->str () == " >" ) {
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ class TestToken : public TestFixture {
106106 TEST_CASE (canFindMatchingBracketsWithTooManyClosing);
107107 TEST_CASE (canFindMatchingBracketsWithTooManyOpening);
108108 TEST_CASE (findClosingBracket);
109+ TEST_CASE (findClosingBracket2);
109110
110111 TEST_CASE (expressionString);
111112
@@ -1084,6 +1085,13 @@ class TestToken : public TestFixture {
10841085 ASSERT (Token::simpleMatch (t, " > struct" ));
10851086 }
10861087
1088+ void findClosingBracket2 () const {
1089+ givenACodeSampleToTokenize var (" const auto g = []<typename T>() {};\n " ); // #11275
1090+
1091+ const Token* const t = Token::findsimplematch (var.tokens (), " <" );
1092+ ASSERT (t && Token::simpleMatch (t->findClosingBracket (), " >" ));
1093+ }
1094+
10871095 void expressionString () const {
10881096 givenACodeSampleToTokenize var1 (" void f() { *((unsigned long long *)x) = 0; }" );
10891097 const Token *const tok1 = Token::findsimplematch (var1.tokens (), " *" );
You can’t perform that action at this time.
0 commit comments