Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #12923: syntaxError for valid template declaration #6603

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ const Token * Token::findClosingBracket() const
}
// save named template parameter
else if (templateParameter && depth == 1 && Token::Match(closing, "[,=]") &&
closing->previous()->isName() && !Token::Match(closing->previous(), "class|typename|."))
closing->previous()->isName() && !Token::Match(closing->previous(), "class|typename|.") && !Token::Match(closing->tokAt(-2), "=|::"))
templateParameters.insert(closing->strAt(-1));
}

Expand Down
11 changes: 11 additions & 0 deletions test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TestToken : public TestFixture {
TEST_CASE(findClosingBracket);
TEST_CASE(findClosingBracket2);
TEST_CASE(findClosingBracket3);
TEST_CASE(findClosingBracket4);

TEST_CASE(expressionString);

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

void findClosingBracket4() {
const SimpleTokenizer var(*this, // #12923
"template<template<class E> class T = std::vector, class U = std::vector<int>, class V = void>\n"
"class C;\n");
const Token *const t = Token::findsimplematch(var.tokens(), "<");
ASSERT(t);
const Token *const closing = t->findClosingBracket();
ASSERT(closing && closing == var.tokens()->tokAt(28));
}

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