[PATCH] D136154: Fix the continuation indenter
Henrik Lafrenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 03:21:09 PDT 2022
hel-ableton created this revision.
hel-ableton added reviewers: JonasToth, MyDeveloperDay, owenpan.
hel-ableton added a project: clang-format.
Herald added a project: All.
hel-ableton requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
When Style.BreakBeforeBinaryOperators is set to FormatStyle::BOS_NonAssignment,
arguments following after a line break should be indented further, which they are
currently not. This attempts to fix that.
Repository:
rG LLVM Github Monorepo
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,6 +6594,32 @@
"(someOtherLongishConditionPart1 || "
"someOtherEvenLongerNestedConditionPart2);",
Style));
+
+ Style = getLLVMStyle();
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ Style.BinPackParameters = false;
+ Style.ContinuationIndentWidth = 2;
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+ EXPECT_EQ(
+ "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"
+ "};",
+ format("struct Derived {"
+ " Derived(int firstArgWithLongName, int secondArgWithLongName, "
+ "int thirdArgWithLongName, int fourthArgWithLongName)"
+ " : Base(firstArgWithLongName, secondArgWithLongName, "
+ "thirdArgWithLongName, fourthArgWithLongName) {}"
+ "};",
+ Style));
}
TEST_F(FormatTest, ExpressionIndentationStrictAlign) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -809,7 +809,8 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136154.468469.patch
Type: text/x-patch
Size: 2283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221018/418553e6/attachment.bin>
More information about the cfe-commits
mailing list