]> granicus.if.org Git - clang/commitdiff
clang-format: Improve formatting of operators forced to new lines.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 19:56:28 +0000 (19:56 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Nov 2013 19:56:28 +0000 (19:56 +0000)
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
unittests/Format/FormatTest.cpp

index 63232beb9f0fe57b562bd10658860875a49e4a6d..1f6c8693d683393a3ff3b63a776ffc5805ca4181 100644 (file)
@@ -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
index c0c78713db2a9cb4d6bef674a7dd57330003977d..794fb1a64b08f125e41203ed216c39c26e239b26 100644 (file)
@@ -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) {