Skip to content

Commit

Permalink
Fix #12789 syntaxError on valid template code (#6457)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 28, 2024
1 parent 2bfeef0 commit 448b951
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ const Token * Token::findClosingBracket() const
depth -= 2;
}
// save named template parameter
else if (templateParameter && depth == 1 && closing->str() == "," &&
else if (templateParameter && depth == 1 && Token::Match(closing, "[,=]") &&
closing->previous()->isName() && !Match(closing->previous(), "class|typename|."))
templateParameters.insert(closing->strAt(-1));
}
Expand Down
9 changes: 9 additions & 0 deletions test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class TestToken : public TestFixture {
TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
TEST_CASE(findClosingBracket);
TEST_CASE(findClosingBracket2);
TEST_CASE(findClosingBracket3);

TEST_CASE(expressionString);

Expand Down Expand Up @@ -1157,6 +1158,14 @@ class TestToken : public TestFixture {
ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">"));
}

void findClosingBracket3() {
const SimpleTokenizer var(*this, // #12789
"template <size_t I = 0, typename... ArgsT, std::enable_if_t<I < sizeof...(ArgsT)>* = nullptr>\n"
"void f();\n");
const Token* const t = Token::findsimplematch(var.tokens(), "<");
ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">"));
}

void expressionString() {
const SimpleTokenizer var1(*this, "void f() { *((unsigned long long *)x) = 0; }");
const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*");
Expand Down

0 comments on commit 448b951

Please sign in to comment.