Skip to content

Commit 448b951

Browse files
Fix #12789 syntaxError on valid template code (#6457)
1 parent 2bfeef0 commit 448b951

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/token.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ const Token * Token::findClosingBracket() const
965965
depth -= 2;
966966
}
967967
// save named template parameter
968-
else if (templateParameter && depth == 1 && closing->str() == "," &&
968+
else if (templateParameter && depth == 1 && Token::Match(closing, "[,=]") &&
969969
closing->previous()->isName() && !Match(closing->previous(), "class|typename|."))
970970
templateParameters.insert(closing->strAt(-1));
971971
}

test/testtoken.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class TestToken : public TestFixture {
108108
TEST_CASE(canFindMatchingBracketsWithTooManyOpening);
109109
TEST_CASE(findClosingBracket);
110110
TEST_CASE(findClosingBracket2);
111+
TEST_CASE(findClosingBracket3);
111112

112113
TEST_CASE(expressionString);
113114

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

1161+
void findClosingBracket3() {
1162+
const SimpleTokenizer var(*this, // #12789
1163+
"template <size_t I = 0, typename... ArgsT, std::enable_if_t<I < sizeof...(ArgsT)>* = nullptr>\n"
1164+
"void f();\n");
1165+
const Token* const t = Token::findsimplematch(var.tokens(), "<");
1166+
ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">"));
1167+
}
1168+
11601169
void expressionString() {
11611170
const SimpleTokenizer var1(*this, "void f() { *((unsigned long long *)x) = 0; }");
11621171
const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*");

0 commit comments

Comments
 (0)