diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3142,7 +3142,8 @@ // initializers. if (Line.IsMultiVariableDeclStmt && (Left.NestingLevel == Line.First->NestingLevel || - startsWithInitStatement(Line))) + ((Left.NestingLevel == Line.First->NestingLevel + 1) && + startsWithInitStatement(Line)))) return false; return Left.Previous && !Left.Previous->isOneOf( tok::l_paren, tok::coloncolon, tok::l_square); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8417,6 +8417,13 @@ verifyFormat( "/*comment*/ switch (int *p, *q; p != q) {\n default:\n break;\n}", Style); + + verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style); + verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style); + verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style); + verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style); + verifyFormat("switch ([](int* p, int* q) {}()) {\n default:\n break;\n}", + Style); } TEST_F(FormatTest, ConditionalExpressionsInBrackets) {