diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 3340b7df2..6438729c5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1520,9 +1520,15 @@ static Token * createAstAtToken(Token *tok, bool cpp) } if (cpp && tok->str() == "{" && iscpp11init(tok)) { + Token * const tok1 = tok; AST_state state(cpp); compileExpression(tok, state); - return tok; + const Token * const endToken = tok; + if (endToken == tok1 || !endToken) + return tok1; + + createAstAtTokenInner(tok1->next(), endToken, cpp); + return endToken->previous(); } return tok; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0993e40dd..3abe63260 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7887,6 +7887,9 @@ private: testAst("a = [&]() -> std::pair { return 0; };\n" "b = [=]() { for (i = 0; i != 10; ++i); };")); + // #9662 + ASSERT_EQUALS("b{[{ stdunique_ptr::0nullptrnullptr:?{", testAst("auto b{[] { std::unique_ptr{0 ? nullptr : nullptr}; }};")); + } void astcase() { @@ -8237,6 +8240,14 @@ private: "};\n" "void e(\n" " int, a f = [] {});\n")) + + // #9537 + ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" + " template a(b) {}\n" + "};\n" + "a c{[] {\n" + " if (0) {}\n" + "}};\n")) } void checkIfCppCast() { ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"