Fix issue 9563: new daca crash: findLambdaEndToken not finding end token (#2472)

This commit is contained in:
Paul Fultz II 2020-01-04 03:45:24 -06:00 committed by amai2012
parent c30d839b98
commit e07801a891
3 changed files with 16 additions and 3 deletions

View File

@ -3431,7 +3431,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
if (tok->str() == "=") { if (tok->str() == "=") {
initArgCount++; initArgCount++;
if (tok->strAt(1) == "[") { if (tok->strAt(1) == "[") {
tok = findLambdaEndToken(tok->next()); const Token* lambdaStart = tok->next();
tok = findLambdaEndToken(lambdaStart);
if (!tok)
throw InternalError(lambdaStart, "Analysis failed (lambda not recognized). If the code is valid then please report this failure.", InternalError::INTERNAL);
} }
} }
} }

View File

@ -765,6 +765,8 @@ static void compileTerm(Token *&tok, AST_state& state)
while (Token::Match(tok, "%name%|%str%")) while (Token::Match(tok, "%name%|%str%"))
tok = tok->next(); tok = tok->next();
} }
if (Token::Match(tok, "%name% %assign%"))
tok = tok->next();
} }
} else if (tok->str() == "{") { } else if (tok->str() == "{") {
const Token *prev = tok->previous(); const Token *prev = tok->previous();
@ -1265,8 +1267,8 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
const Token * const endToken2 = tok->link(); const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr) for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp); tok = createAstAtToken(tok, cpp);
} else if (Token::simpleMatch(tok->link(), "] (") && Token::Match(tok->link()->linkAt(1), ") .|{")) { } else if (const Token * lambdaEnd = findLambdaEndScope(tok)) {
Token *bodyStart = tok->link()->linkAt(1)->next(); Token *bodyStart = lambdaEnd->link();
if (Token::Match(bodyStart, ". %name%") && bodyStart->originalName() == "->") { if (Token::Match(bodyStart, ". %name%") && bodyStart->originalName() == "->") {
bodyStart = bodyStart->next(); bodyStart = bodyStart->next();
while (Token::Match(bodyStart, "%name%|::")) while (Token::Match(bodyStart, "%name%|::"))

View File

@ -8168,6 +8168,14 @@ private:
" if (a<b, decltype(0)>::d) {}\n" " if (a<b, decltype(0)>::d) {}\n"
" });\n" " });\n"
"}\n")) "}\n"))
// #9563
ASSERT_NO_THROW(tokenizeAndStringify("template <typename> struct a;\n"
"template <typename b, typename... c> struct a<b(c...)> {\n"
" template <typename d> a(d);\n"
"};\n"
"void e(\n"
" int, a<void()> f = [] {});\n"))
} }
void checkIfCppCast() { void checkIfCppCast() {
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"