diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 4f4e85b15..8c55efe8a 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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); } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 947b9d575..f2ec89fef 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {