Fix syntaxError with const lambda (refs #11275) (#5571)

This commit is contained in:
chrchr-github 2023-10-20 15:32:46 +02:00 committed by GitHub
parent 0070a78101
commit b61feaf77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -910,7 +910,7 @@ const Token * Token::findClosingBracket() const
if (!mPrevious) if (!mPrevious)
return nullptr; return nullptr;
if (!(mPrevious->isName() || if (!(mPrevious->isName() || Token::simpleMatch(mPrevious, "]") ||
Token::Match(mPrevious->previous(), "operator %op% <") || Token::Match(mPrevious->previous(), "operator %op% <") ||
Token::Match(mPrevious->tokAt(-2), "operator [([] [)]] <"))) Token::Match(mPrevious->tokAt(-2), "operator [([] [)]] <")))
return nullptr; return nullptr;
@ -939,7 +939,7 @@ const Token * Token::findClosingBracket() const
return nullptr; return nullptr;
// we can make some guesses for template parameters // we can make some guesses for template parameters
else if (closing->str() == "<" && closing->previous() && 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)) (templateParameter ? templateParameters.find(closing->strAt(-1)) == templateParameters.end() : true))
++depth; ++depth;
else if (closing->str() == ">") { else if (closing->str() == ">") {

View File

@ -106,6 +106,7 @@ private:
TEST_CASE(canFindMatchingBracketsWithTooManyClosing); TEST_CASE(canFindMatchingBracketsWithTooManyClosing);
TEST_CASE(canFindMatchingBracketsWithTooManyOpening); TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
TEST_CASE(findClosingBracket); TEST_CASE(findClosingBracket);
TEST_CASE(findClosingBracket2);
TEST_CASE(expressionString); TEST_CASE(expressionString);
@ -1084,6 +1085,13 @@ private:
ASSERT(Token::simpleMatch(t, "> struct")); 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 { void expressionString() const {
givenACodeSampleToTokenize var1("void f() { *((unsigned long long *)x) = 0; }"); givenACodeSampleToTokenize var1("void f() { *((unsigned long long *)x) = 0; }");
const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*"); const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*");