Fix issue 9145: Syntax error on valid C++14 code (#1860)

This commit is contained in:
Paul Fultz II 2019-05-31 01:05:01 -05:00 committed by Daniel Marjamäki
parent f66cbac0a4
commit 33130bdff6
2 changed files with 21 additions and 2 deletions

View File

@ -3847,7 +3847,7 @@ void Tokenizer::createLinks2()
while (!type.empty() && type.top()->str() == "<") { while (!type.empty() && type.top()->str() == "<") {
const Token* end = type.top()->findClosingBracket(); const Token* end = type.top()->findClosingBracket();
if (Token::Match(end, "> ;|%comp%")) if (Token::Match(end, "> %comp%|;|."))
break; break;
// Variable declaration // Variable declaration
if (Token::Match(end, "> %var% ;") && (type.top()->tokAt(-2) == nullptr || Token::Match(type.top()->tokAt(-2), ";|}|{"))) 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() == ">>") if (token->str() == ">>")
continue; continue;
if (token->next() && if (token->next() &&
!Token::Match(token->next(), "%name%|%comp%|&|&&|*|::|,|(|)|{|}|;|[|:") && !Token::Match(token->next(), "%name%|%comp%|&|&&|*|::|,|(|)|{|}|;|[|:|.") &&
!Token::simpleMatch(token->next(), ". . .") && !Token::simpleMatch(token->next(), ". . .") &&
!Token::Match(token->next(), "&& %name% =")) !Token::Match(token->next(), "&& %name% ="))
continue; continue;

View File

@ -4873,6 +4873,25 @@ private:
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link()); ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link());
} }
{
// #9145
const char code[] = "template <typename a, a> struct b {\n"
" template <typename c> constexpr void operator()(c &&) const;\n"
"};\n"
"template <int d> struct e { b<int, d> f; };\n"
"template <int g> using h = e<g>;\n"
"template <int g> h<g> i;\n"
"template <typename a, a d>\n"
"template <typename c>\n"
"constexpr void b<a, d>::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() { void simplifyString() {