[PATCH] D136154: [clang-format] Fix the continuation indenter
Henrik Lafrenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 19 05:24:21 PDT 2022
hel-ableton updated this revision to Diff 468878.
hel-ableton added a comment.
Using verifyFormat() now instead of EXPECT_EQ()
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136154/new/
https://reviews.llvm.org/D136154
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6594,7 +6594,25 @@
"(someOtherLongishConditionPart1 || "
"someOtherEvenLongerNestedConditionPart2);",
Style));
-}
+
+ Style = getLLVMStyle();
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ Style.BinPackParameters = false;
+ Style.ContinuationIndentWidth = 2;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+ verifyFormat(
+ "struct Derived {\n"
+ " Derived(\n"
+ " int firstArgWithLongName,\n"
+ " int secondArgWithLongName,\n"
+ " int thirdArgWithLongName,\n"
+ " int fourthArgWithLongName)\n"
+ " : Base(\n"
+ " firstArgWithLongName,\n"
+ " secondArgWithLongName,\n"
+ " thirdArgWithLongName,\n"
+ " fourthArgWithLongName) {}\n"
+ "};", Style);}
TEST_F(FormatTest, ExpressionIndentationStrictAlign) {
FormatStyle Style = getLLVMStyle();
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -809,8 +809,10 @@
// Indent relative to the RHS of the expression unless this is a simple
// assignment without binary expression on the RHS. Also indent relative to
// unary operators and the colons of constructor initializers.
- if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
+ if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None ||
+ Style.BreakBeforeBinaryOperators == FormatStyle::BOS_NonAssignment) {
CurrentState.LastSpace = State.Column;
+ }
} else if (Previous.is(TT_InheritanceColon)) {
CurrentState.Indent = State.Column;
CurrentState.LastSpace = State.Column;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136154.468878.patch
Type: text/x-patch
Size: 2026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221019/37a7600f/attachment.bin>
More information about the cfe-commits
mailing list