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

            Bug ID: 45338
           Summary: AllowShortIfStatementsOnASingleLine: WithoutElse
                    broken
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: pablomg+l...@eskapa.be
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

$ cat test.cpp
int main() {

if (true) { function(); }

if (true) function();

if (true) { function(); } else function();

if (true) { function(); } else { function(); }

if (true) function(); else function();

if (true) function(); else { function(); }

}

$ clang-format test.cpp -style="{BasedOnStyle: google, BreakBeforeBraces:
Allman, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main()
{
  if (true) { function(); }

  if (true) function();

  if (true) { function(); }
  else
    function();

  if (true) { function(); }
  else
  {
    function();
  }

  if (true)
    function();
  else
    function();

  if (true)
    function();
  else
  {
    function();
  }
}


According to the clang-format 11 documentation,
AllowShortIfStatementsOnASingleLine: WithoutElse means the following: "Without
else put short ifs on the same line only if the else is not a compound
statement.". So the expected result should be:

$ clang-format test.cpp -style="{BasedOnStyle: google, BreakBeforeBraces:
Allman, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main()
{
  if (true) { function(); }

  if (true) function();

  if (true) { function(); }
  else
    function();

  if (true)
  {
    function();
  }
  else
  {
    function();
  }

  if (true) function();
  else
    function();

  if (true)
    function();
  else
  {
    function();
  }
}

I don't use BreakBeforeBraces: Attach but it seems broken too:
$ ../bin/clang-format test.cpp -style="{BasedOnStyle: google,
BreakBeforeBraces: Attach, AllowShortBlocksOnASingleLine: Always,
AllowShortIfStatementsOnASingleLine: WithoutElse}"
int main() {
  if (true) { function(); }

  if (true) function();

  if (true) {
    function();
  } else
    function();

  if (true) {
    function();
  } else {
    function();
  }

  if (true)
    function();
  else
    function();

  if (true)
    function();
  else {
    function();
  }
}

Might be related to bug 25010 (https://bugs.llvm.org/show_bug.cgi?id=25010) but
I'm not sure.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to