[llvm-bugs] [Bug 44192] New: Ignore AllowShort* when ColumnLimit is reach with Allman style

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 1 04:37:59 PST 2019


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

            Bug ID: 44192
           Summary: Ignore AllowShort* when ColumnLimit is reach with
                    Allman style
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pablomg+llvm at eskapa.be
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

$ cat test.cpp
if (function()) { anotherfunction(); }

if (longfunction()) { anotherlongfunction(); }

while (function()) { anotherfunction(); }

while (longfunction()) { anotherlongfunction(); }
$ clang-format test.cpp -style="{BreakBeforeBraces: Allman,
AllowShortBlocksOnASingleLine: Always, AllowShortIfStatementsOnASingleLine:
Always, AllowShortLoopsOnASingleLine: true, ColumnLimit: 45}"
if (function()) { anotherfunction(); }

if (longfunction())
{ anotherlongfunction(); }

while (function()) { anotherfunction(); }

while (longfunction())
{ anotherlongfunction(); }
$ clang-format test.cpp -style="{BreakBeforeBraces: Attach,
AllowShortBlocksOnASingleLine: Always, AllowShortIfStatementsOnASingleLine:
Always, AllowShortLoopsOnASingleLine: true, ColumnLimit: 45}"
if (function()) { anotherfunction(); }

if (longfunction()) {
  anotherlongfunction();
}

while (function()) { anotherfunction(); }

while (longfunction()) {
  anotherongfunction();
}

Expected result:
$ clang-format test.cpp -style="{BreakBeforeBraces: Allman,
AllowShortBlocksOnASingleLine: Always, AllowShortIfStatementsOnASingleLine:
Always, AllowShortLoopsOnASingleLine: true, ColumnLimit: 45}"
if (function()) { anotherfunction(); }

if (longfunction())
{ 
  anotherlongfunction();
}

while (function()) { anotherfunction(); }

while (longfunction())
{
  anotherlongfunction();
}

>From what I understand, in Allman style, clang-format puts the block in a
single line, notice the line length is superior to the column limit and then
breaks the line where it is best instead of reverting putting the block in a
single line like the attach style does.

-- 
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/20191201/71aa3fd3/attachment-0001.html>


More information about the llvm-bugs mailing list