Skip to content

Commit

Permalink
Fix syntaxError with const lambda (refs #11275) (#5571)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 20, 2023
1 parent 0070a78 commit b61feaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() == ">") {
Expand Down
8 changes: 8 additions & 0 deletions test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class TestToken : public TestFixture {
TEST_CASE(canFindMatchingBracketsWithTooManyClosing);
TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
TEST_CASE(findClosingBracket);
TEST_CASE(findClosingBracket2);

TEST_CASE(expressionString);

Expand Down Expand Up @@ -1084,6 +1085,13 @@ class TestToken : public TestFixture {
ASSERT(Token::simpleMatch(t, "> struct"));
}

void findClosingBracket2() const {
givenACodeSampleToTokenize var("const auto g = []<typename T>() {};\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(), "*");
Expand Down

0 comments on commit b61feaf

Please sign in to comment.