mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-06 01:19:28 +00:00
[clang-format] Fix a bug in ContinuationIndenter (#66354)
See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of #58592.
This commit is contained in:
parent
0b8df841f9
commit
5ed94c6e3d
@ -876,15 +876,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
||||
FormatStyle::BCIS_AfterColon) {
|
||||
CurrentState.Indent = State.Column;
|
||||
CurrentState.LastSpace = State.Column;
|
||||
} else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
|
||||
TT_CtorInitializerColon)) &&
|
||||
} else if (Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) {
|
||||
CurrentState.LastSpace = State.Column;
|
||||
} else if (Previous.is(TT_BinaryOperator) &&
|
||||
((Previous.getPrecedence() != prec::Assignment &&
|
||||
(Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
|
||||
Previous.NextOperator)) ||
|
||||
Current.StartsBinaryExpression)) {
|
||||
// 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.
|
||||
// assignment without binary expression on the RHS.
|
||||
if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
|
||||
CurrentState.LastSpace = State.Column;
|
||||
} else if (Previous.is(TT_InheritanceColon)) {
|
||||
|
@ -7108,6 +7108,29 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) {
|
||||
"(someOtherLongishConditionPart1 || "
|
||||
"someOtherEvenLongerNestedConditionPart2);",
|
||||
Style);
|
||||
|
||||
Style = getLLVMStyleWithColumns(20);
|
||||
Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
|
||||
Style.BinPackParameters = false;
|
||||
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
|
||||
Style.ContinuationIndentWidth = 2;
|
||||
verifyFormat("struct Foo {\n"
|
||||
" Foo(\n"
|
||||
" int arg1,\n"
|
||||
" int arg2)\n"
|
||||
" : Base(\n"
|
||||
" arg1,\n"
|
||||
" arg2) {}\n"
|
||||
"};",
|
||||
Style);
|
||||
verifyFormat("return abc\n"
|
||||
" ? foo(\n"
|
||||
" a,\n"
|
||||
" b,\n"
|
||||
" bar(\n"
|
||||
" abc))\n"
|
||||
" : g(abc);",
|
||||
Style);
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, ExpressionIndentationStrictAlign) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user