[llvm-bugs] [Bug 37110] New: [Formatter/ObjC] Line break between exclamation mark ! and method call if line length = ColumnLimit+1

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 12 10:36:08 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37110

            Bug ID: 37110
           Summary: [Formatter/ObjC] Line break between exclamation mark !
                    and method call if line length = ColumnLimit+1
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at dzhang.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Line breaking behavior for lines of length ColumnLimit+1 of the form ![obj
methodCall] chooses to break the line between the bang/not operator and the
method call, which is undesirable.

----------------------------------------

input.m:

- (void)test {
  // these three with variables wrap as expected
  if
(!someLongBooleanVariableNameUsedInAnIf01234567801234567801234567801234567890123456789)
    return;

  if (someLongBooleanVariableNameUsedInAnIf ||
!aDifferentLongBooleanVariable11)
    return;

  if (someLongBooleanVariableNameUsedInAnIf ||
!aDifferentLongBooleanVariable111)
    return;

  // these two with method calls wrap badly
  if ([self someLongMethodThatReturnsBoolean] || ![self
aDifferentBooleanMethod])
    return;

  if (![self
someLongMethodThatReturnsBoolean0123456780123456780123456780123456])
    return;
}

$ clang-format -style=llvm input.m

- (void)test {
  // these three with variables wrap as expected
  if
(!someLongBooleanVariableNameUsedInAnIf01234567801234567801234567801234567890123456789)
    return;

  if (someLongBooleanVariableNameUsedInAnIf ||
!aDifferentLongBooleanVariable11)
    return;

  if (someLongBooleanVariableNameUsedInAnIf ||
      !aDifferentLongBooleanVariable111)
    return;

  // these two with method calls wrap badly
  if ([self someLongMethodThatReturnsBoolean] || !
                                                 [self
aDifferentBooleanMethod])
    return;

  if (!
      [self
someLongMethodThatReturnsBoolean0123456780123456780123456780123456])
    return;
}

$ clang-format --version
clang-format version 7.0.0 (tags/google/stable/2018-01-11)

----------------------------------------

Notice that if I use variables, they wrap as expected when the lines are 80 and
81 chars long, but when using method calls ending at column 81, the formatter
causes bad line breaking.

I have not been able to find a combination of config options that avoids this
behavior.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180412/557556bf/attachment.html>


More information about the llvm-bugs mailing list