HazardyKnusperkeks created this revision. HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius. HazardyKnusperkeks added a project: clang-format. HazardyKnusperkeks requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
According to https://lists.llvm.org/pipermail/cfe-dev/2021-January/067481.html Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D94906 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13481,6 +13481,57 @@ "#endif", AllmanBraceStyle); + EXPECT_EQ(AllmanBraceStyle.AllowShortLambdasOnASingleLine, FormatStyle::SLS_All); + + verifyFormat("[](int i) { return i + 2; };\n" + "[](int i, int j)\n" + "{\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + "};\n" + "void foo()\n" + "{\n" + " auto shortLambda = [](int i) { return i + 2; };\n" + " auto longLambda = [](int i, int j)\n" + " {\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + " };\n" + "}", + AllmanBraceStyle); + + AllmanBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None; + + verifyFormat("[](int i)\n" + "{\n" + " return i + 2;\n" + "};\n" + "[](int i, int j)\n" + "{\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + "};\n" + "void foo()\n" + "{\n" + " auto shortLambda = [](int i)\n" + " {\n" + " return i + 2;\n" + " };\n" + " auto longLambda = [](int i, int j)\n" + " {\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + " };\n" + "}", + AllmanBraceStyle); + + // Reset + AllmanBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; + // This shouldn't affect ObjC blocks.. verifyFormat("[self doSomeThingWithACompletionHandler:^{\n" " // ...\n" Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -817,6 +817,7 @@ Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock; Expanded.BraceWrapping.BeforeCatch = true; Expanded.BraceWrapping.BeforeElse = true; + Expanded.BraceWrapping.BeforeLambdaBody = true; break; case FormatStyle::BS_Whitesmiths: Expanded.BraceWrapping.AfterCaseLabel = true;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13481,6 +13481,57 @@ "#endif", AllmanBraceStyle); + EXPECT_EQ(AllmanBraceStyle.AllowShortLambdasOnASingleLine, FormatStyle::SLS_All); + + verifyFormat("[](int i) { return i + 2; };\n" + "[](int i, int j)\n" + "{\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + "};\n" + "void foo()\n" + "{\n" + " auto shortLambda = [](int i) { return i + 2; };\n" + " auto longLambda = [](int i, int j)\n" + " {\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + " };\n" + "}", + AllmanBraceStyle); + + AllmanBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None; + + verifyFormat("[](int i)\n" + "{\n" + " return i + 2;\n" + "};\n" + "[](int i, int j)\n" + "{\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + "};\n" + "void foo()\n" + "{\n" + " auto shortLambda = [](int i)\n" + " {\n" + " return i + 2;\n" + " };\n" + " auto longLambda = [](int i, int j)\n" + " {\n" + " auto x = i + j;\n" + " auto y = i * j;\n" + " return x ^ y;\n" + " };\n" + "}", + AllmanBraceStyle); + + // Reset + AllmanBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; + // This shouldn't affect ObjC blocks.. verifyFormat("[self doSomeThingWithACompletionHandler:^{\n" " // ...\n" Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -817,6 +817,7 @@ Expanded.IndentExternBlock = FormatStyle::IEBS_AfterExternBlock; Expanded.BraceWrapping.BeforeCatch = true; Expanded.BraceWrapping.BeforeElse = true; + Expanded.BraceWrapping.BeforeLambdaBody = true; break; case FormatStyle::BS_Whitesmiths: Expanded.BraceWrapping.AfterCaseLabel = true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits