Skip to content

Commit

Permalink
Partial fix for #12923: syntaxError for valid template declaration
Browse files Browse the repository at this point in the history
This avoids saving names that appear after the assignment operator within a template parameter declaration.
  • Loading branch information
ehlert-battelle committed Jul 15, 2024
1 parent 03ac57e commit 5ae0525
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -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

0 comments on commit 5ae0525

Please sign in to comment.