From 33130bdff6e55d82ec82eb633218c1b6fb3bd23c Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 31 May 2019 01:05:01 -0500 Subject: [PATCH] Fix issue 9145: Syntax error on valid C++14 code (#1860) --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bfb2a361e..1ceda3ce7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3847,7 +3847,7 @@ void Tokenizer::createLinks2() while (!type.empty() && type.top()->str() == "<") { const Token* end = type.top()->findClosingBracket(); - if (Token::Match(end, "> ;|%comp%")) + if (Token::Match(end, "> %comp%|;|.")) break; // Variable declaration if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{"))) @@ -3871,7 +3871,7 @@ void Tokenizer::createLinks2() if (token->str() == ">>") continue; if (token->next() && - !Token::Match(token->next(), "%name%|%comp%|&|&&|*|::|,|(|)|{|}|;|[|:") && + !Token::Match(token->next(), "%name%|%comp%|&|&&|*|::|,|(|)|{|}|;|[|:|.") && !Token::simpleMatch(token->next(), ". . .") && !Token::Match(token->next(), "&& %name% =")) continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7d5a976b9..02fe3f871 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4873,6 +4873,25 @@ private: tokenizer.tokenize(istr, "test.cpp"); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link()); } + + { + // #9145 + const char code[] = "template struct b {\n" + " template constexpr void operator()(c &&) const;\n" + "};\n" + "template struct e { b f; };\n" + "template using h = e;\n" + "template h i;\n" + "template \n" + "template \n" + "constexpr void b::operator()(c &&) const {\n" + " i<3>.f([] {});\n" + "}\n"; + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> . f (")->link()); + } } void simplifyString() {