Skip to content

Commit ce96ec2

Browse files
pfultz2danmar
authored andcommitted
Fix issue 9136: Syntax error on valid C++14 code: createLinks2() failed
1 parent 8cbd9b0 commit ce96ec2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎lib/tokenize.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3870,7 +3870,8 @@ void Tokenizer::createLinks2()
38703870
continue;
38713871
}
38723872
// if > is followed by [ .. "new a<b>[" is expected
3873-
if (token->strAt(1) == "[") {
3873+
// unless this is from varidiac expansion
3874+
if (token->strAt(1) == "[" && !Token::simpleMatch(token->tokAt(-3), ". . . >")) {
38743875
Token *prev = type.top()->previous();
38753876
while (prev && Token::Match(prev->previous(), ":: %name%"))
38763877
prev = prev->tokAt(-2);

‎test/testtokenize.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,6 +4808,18 @@ class TestTokenizer : public TestFixture {
48084808
tokenizer.tokenize(istr, "test.cpp");
48094809
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link());
48104810
}
4811+
4812+
{
4813+
// #9136
4814+
const char code[] = "template <char> char * a;\n"
4815+
"template <char... b> struct c {\n"
4816+
" void d() { a<b...>[0]; }\n"
4817+
"};\n";
4818+
Tokenizer tokenizer(&settings0, this);
4819+
std::istringstream istr(code);
4820+
tokenizer.tokenize(istr, "test.cpp");
4821+
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link());
4822+
}
48114823
}
48124824

48134825
void simplifyString() {

0 commit comments

Comments
 (0)