From 8b156e2a040d7a652e821878b68822041f65d71a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 8 Nov 2013 19:56:28 +0000 Subject: [PATCH] clang-format: Improve formatting of operators forced to new lines. Before: unsigned ContentSize = sizeof(int16_t) // DWARF ARange version number + sizeof(int32_t) // Offset of CU in the .debug_info section + sizeof(int8_t) // Pointer Size (in bytes) + sizeof(int8_t); // Segment Size (in bytes) After: unsigned ContentSize = sizeof(int16_t) // DWARF ARange version number + sizeof(int32_t) // Offset of CU in the .debug_info section + sizeof(int8_t) // Pointer Size (in bytes) + sizeof(int8_t); // Segment Size (in bytes) This fixes llvm.org/PR17687. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194276 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 10 ++++++---- unittests/Format/FormatTest.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 63232beb9f..1f6c8693d6 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -439,10 +439,12 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) { State.Stack[i].BreakBeforeParameter = true; } - const FormatToken *TokenBefore = Current.getPreviousNonComment(); - if (TokenBefore && !TokenBefore->isOneOf(tok::comma, tok::semi) && - TokenBefore->Type != TT_TemplateCloser && - TokenBefore->Type != TT_BinaryOperator && !TokenBefore->opensScope()) + if (PreviousNonComment && + !PreviousNonComment->isOneOf(tok::comma, tok::semi) && + PreviousNonComment->Type != TT_TemplateCloser && + PreviousNonComment->Type != TT_BinaryOperator && + Current.Type != TT_BinaryOperator && + !PreviousNonComment->opensScope()) State.Stack.back().BreakBeforeParameter = true; // If we break after { or the [ of an array initializer, we should also break diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c0c78713db..794fb1a64b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2668,6 +2668,14 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { " > ccccc) {\n" "}", Style); + + // Forced by comments. + verifyFormat( + "unsigned ContentSize =\n" + " sizeof(int16_t) // DWARF ARange version number\n" + " + sizeof(int32_t) // Offset of CU in the .debug_info section\n" + " + sizeof(int8_t) // Pointer Size (in bytes)\n" + " + sizeof(int8_t); // Segment Size (in bytes)"); } TEST_F(FormatTest, ConstructorInitializers) { -- 2.40.0