Fix issue 9136: Syntax error on valid C++14 code: createLinks2() failed

This commit is contained in:
Paul Fultz II 2019-05-19 19:06:12 +02:00 committed by Daniel Marjamäki
parent 8cbd9b03aa
commit ce96ec2773
2 changed files with 14 additions and 1 deletions

View File

@ -3870,7 +3870,8 @@ void Tokenizer::createLinks2()
continue;
}
// if > is followed by [ .. "new a<b>[" 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);

View File

@ -4808,6 +4808,18 @@ private:
tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link());
}
{
// #9136
const char code[] = "template <char> char * a;\n"
"template <char... b> struct c {\n"
" void d() { a<b...>[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() {