Fix crash with lambda capture (#1960)

This commit is contained in:
Paul Fultz II 2019-07-06 03:46:17 -05:00 committed by amai2012
parent 2bd026dd2a
commit 65af02f0cf
3 changed files with 13 additions and 2 deletions

View File

@ -668,7 +668,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
const Token *lambdaStartToken = lambdaEndToken->link(); const Token *lambdaStartToken = lambdaEndToken->link();
const Token * argStart = lambdaStartToken->astParent(); const Token * argStart = lambdaStartToken->astParent();
const Token * funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent(); const Token * funcStart = Token::simpleMatch(argStart, "[") ? argStart : argStart->astParent();
addGlobalFunction(scope, tok, argStart, funcStart); const Function * function = addGlobalFunction(scope, tok, argStart, funcStart);
if (!function)
mTokenizer->syntaxError(tok);
tok = lambdaStartToken; tok = lambdaStartToken;
} else if (tok->str() == "{") { } else if (tok->str() == "{") {
if (isExecutableScope(tok)) { if (isExecutableScope(tok)) {
@ -679,6 +681,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
tok = tok->link(); tok = tok->link();
} }
} }
// syntax error?
if (!scope)
mTokenizer->syntaxError(tok);
} }
} }
} }

View File

@ -6609,7 +6609,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
Token *eq = tok2; Token *eq = tok2;
while (tok2) { while (tok2) {
if (Token::Match(tok2, "{|(")) if (Token::Match(tok2, "{|(|["))
tok2 = tok2->link(); tok2 = tok2->link();
else if (!isC() && tok2->str() == "<" && tok2->previous()->isName() && !tok2->previous()->varId()) else if (!isC() && tok2->str() == "<" && tok2->previous()->isName() && !tok2->previous()->varId())

View File

@ -7840,6 +7840,12 @@ private:
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i] {}; }"))
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i = std::move(i)] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [&, i = std::move(i)] {}; }"))
ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, i = std::move(i)] {}; }")) ASSERT_NO_THROW(tokenizeAndStringify("auto f(int& i) { return [=, i = std::move(i)] {}; }"))
ASSERT_NO_THROW(tokenizeAndStringify("struct c {\n"
" void d() {\n"
" int a;\n"
" auto b = [this, a] {};\n"
" }\n"
"};\n"))
} }
void noCrash1() { void noCrash1() {