From ce96ec27739f426518baa2f8a341ea84bf41316a Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 19 May 2019 19:06:12 +0200 Subject: [PATCH] Fix issue 9136: Syntax error on valid C++14 code: createLinks2() failed --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e37c49fc6..42c242923 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3870,7 +3870,8 @@ void Tokenizer::createLinks2() continue; } // if > is followed by [ .. "new a[" is expected - if (token->strAt(1) == "[") { + // unless this is from varidiac expansion + if (token->strAt(1) == "[" && !Token::simpleMatch(token->tokAt(-3), ". . . >")) { Token *prev = type.top()->previous(); while (prev && Token::Match(prev->previous(), ":: %name%")) prev = prev->tokAt(-2); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index db70c90cc..ca6f3d76a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4808,6 +4808,18 @@ private: tokenizer.tokenize(istr, "test.cpp"); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link()); } + + { + // #9136 + const char code[] = "template char * a;\n" + "template struct c {\n" + " void d() { a[0]; }\n" + "};\n"; + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link()); + } } void simplifyString() {