[PATCH] D115972: [clang-format] Fix AlignConsecutiveAssignments breaking lambda formatting.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 1 00:18:20 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd33cca762fa: [clang-format] Fix AlignConsecutiveAssignments breaking lambda formatting. (authored by curdeius).
Changed prior to commit:
https://reviews.llvm.org/D115972?vs=404438&id=404832#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115972/new/
https://reviews.llvm.org/D115972
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16571,6 +16571,43 @@
"int yy = 1; ///specificlennospace\n"
"int zzz = 2;\n",
Alignment));
+
+ verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n"
+ "auto b = [] {\n"
+ " f();\n"
+ " return;\n"
+ "};",
+ Alignment);
+ verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n"
+ "auto b = g([] {\n"
+ " f();\n"
+ " return;\n"
+ "});",
+ Alignment);
+ verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n"
+ "auto b = g(param, [] {\n"
+ " f();\n"
+ " return;\n"
+ "});",
+ Alignment);
+ verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n"
+ "auto b = [] {\n"
+ " if (condition) {\n"
+ " return;\n"
+ " }\n"
+ "};",
+ Alignment);
+
+ verifyFormat("auto b = f(aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " ccc ? aaaaa : bbbbb,\n"
+ " dddddddddddddddddddddddddd);",
+ Alignment);
+ // FIXME: https://llvm.org/PR53497
+ // verifyFormat("auto aaaaaaaaaaaa = f();\n"
+ // "auto b = f(aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ // " ccc ? aaaaa : bbbbb,\n"
+ // " dddddddddddddddddddddddddd);",
+ // Alignment);
}
TEST_F(FormatTest, AlignConsecutiveBitFields) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -344,6 +344,10 @@
if (Changes[ScopeStart - 1].Tok->is(TT_FunctionDeclarationName))
return true;
+ // Lambda.
+ if (Changes[ScopeStart - 1].Tok->is(TT_LambdaLBrace))
+ return false;
+
// Continued function declaration
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->is(TT_FunctionDeclarationName))
@@ -352,8 +356,13 @@
// Continued function call
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
- Changes[ScopeStart - 1].Tok->is(tok::l_paren))
+ Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
+ Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
+ if (Changes[i].Tok->MatchingParen &&
+ Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace))
+ return false;
return Style.BinPackArguments;
+ }
// Ternary operator
if (Changes[i].Tok->is(TT_ConditionalExpr))
@@ -372,8 +381,15 @@
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
- Changes[i].Tok->isNot(tok::r_brace))
+ Changes[i].Tok->isNot(tok::r_brace)) {
+ for (unsigned OuterScopeStart : llvm::reverse(ScopeStack)) {
+ // Lambda.
+ if (OuterScopeStart > Start &&
+ Changes[OuterScopeStart - 1].Tok->is(TT_LambdaLBrace))
+ return false;
+ }
return true;
+ }
return false;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115972.404832.patch
Type: text/x-patch
Size: 3636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220201/24beb40e/attachment.bin>
More information about the cfe-commits
mailing list