curdeius created this revision. curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan. curdeius requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/53843. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D119814 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ 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);
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits