AST: Fix AST when returning list of lambda functions

This commit is contained in:
Daniel Marjamäki 2019-10-22 18:39:44 +02:00
parent 3699227b12
commit cf1dd2e6f6
2 changed files with 13 additions and 1 deletions

View File

@ -1176,7 +1176,7 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
} else if (tok->str() == "[") {
} else if (cpp && tok->str() == "[") {
if (isLambdaCaptureList(tok)) {
tok = tok->astOperand1();
if (tok->str() == "(")
@ -1184,6 +1184,11 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
} else if (Token::simpleMatch(tok->link(), "] (") && Token::simpleMatch(tok->link()->linkAt(1), ") {")) {
tok = tok->link()->linkAt(1)->next();
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
}
}
}

View File

@ -7606,6 +7606,13 @@ private:
// 8628
ASSERT_EQUALS("f{([( switchx( 1case y++", testAst("f([](){switch(x){case 1:{++y;}}});"));
ASSERT_EQUALS("{return ab=",
testAst("return {\n"
" [=]() {\n"
" a = b;\n"
" }\n"
"};\n"));
}
void astcase() {