[PATCH] D125162: [clang-format] fix alignment w/o binpacked args
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 16 01:25:15 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe57f57841fbb: [clang-format] fix alignment w/o binpacked args (authored by cha5on, committed by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125162/new/
https://reviews.llvm.org/D125162
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
@@ -17318,6 +17318,23 @@
// " ccc ? aaaaa : bbbbb,\n"
// " dddddddddddddddddddddddddd);",
// Alignment);
+
+ // Confirm proper handling of AlignConsecutiveAssignments with
+ // BinPackArguments.
+ // See https://llvm.org/PR55360
+ Alignment = getLLVMStyleWithColumns(50);
+ Alignment.AlignConsecutiveAssignments.Enabled = true;
+ Alignment.BinPackArguments = false;
+ verifyFormat("int a_long_name = 1;\n"
+ "auto b = B({a_long_name, a_long_name},\n"
+ " {a_longer_name_for_wrap,\n"
+ " a_longer_name_for_wrap});",
+ Alignment);
+ verifyFormat("int a_long_name = 1;\n"
+ "auto b = B{{a_long_name, a_long_name},\n"
+ " {a_longer_name_for_wrap,\n"
+ " a_longer_name_for_wrap}};",
+ Alignment);
}
TEST_F(FormatTest, AlignConsecutiveBitFields) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -371,6 +371,9 @@
return false;
if (Changes[ScopeStart].NewlinesBefore > 0)
return false;
+ if (Changes[i].Tok->is(tok::l_brace) &&
+ Changes[i].Tok->is(BK_BracedInit))
+ return true;
return Style.BinPackArguments;
}
@@ -387,6 +390,14 @@
Changes[i].Tok->Previous->is(TT_ConditionalExpr))
return true;
+ // Continued direct-list-initialization using braced list.
+ if (ScopeStart > Start + 1 &&
+ Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
+ Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
+ Changes[i].Tok->is(tok::l_brace) &&
+ Changes[i].Tok->is(BK_BracedInit))
+ return true;
+
// Continued braced list.
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125162.429640.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220516/1e174ad5/attachment-0001.bin>
More information about the cfe-commits
mailing list