[PATCH] D136154: [clang-format] Fix the continuation indenter
Henrik Lafrenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 19 07:25:53 PDT 2022
hel-ableton updated this revision to Diff 468907.
hel-ableton added a comment.
Fixed missing newline.
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,6 +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) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -800,8 +800,9 @@
FormatStyle::BCIS_AfterColon) {
CurrentState.Indent = State.Column;
CurrentState.LastSpace = State.Column;
- } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
- TT_CtorInitializerColon)) &&
+ } else if (Previous.is(TT_CtorInitializerColon)) {
+ CurrentState.LastSpace = State.Column;
+ } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr)) &&
((Previous.getPrecedence() != prec::Assignment &&
(Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
Previous.NextOperator)) ||
@@ -809,8 +810,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.468907.patch
Type: text/x-patch
Size: 2641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221019/557db2f0/attachment.bin>
More information about the cfe-commits
mailing list