Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-format: Allman option does not work reliably #22103

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22104
Status REOPENED
Importance P normal
Reported by Steven Evergreen (evergreenthrowaway@gmail.com)
Reported on 2015-01-06 09:56:52 -0800
Last modified on 2019-09-30 12:36:32 -0700
Version unspecified
Hardware Macintosh MacOS X
CC djasper@google.com, evergreenthrowaway@gmail.com, klimek@google.com, llvm-bugs@lists.llvm.org, mydeveloperday@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
According to the documentation, Allman enforces "Always break before braces"

Unfortunately, it doesn't seem to be doing that for if statements or for loops
(see below).

Repros with 3.5.0 and http://llvm.org/git/clang.git
d287557ca022716d56a6ff4e7f8ba44a08ef9737

Thanks!

INPUT
void function() {
    for (unsigned i = 0; i < 5; i++) {
        if (YES) {
        }
        else {
        }
    }
}

OUTPUT
void function()
{
    for (unsigned i = 0; i < 5; i++) {
        if (YES) {
        }
        else
        {
        }
    }
}
Quuxplusone commented 9 years ago
On current trunk:
echo 'void f(){for(;;){if(a){}else{}}}' |./bin/clang-format -
style='{"BasedOnStyle": "LLVM", "BreakBeforeBraces": "Allman"}'
void f()
{
  for (;;)
  {
    if (a)
    {
    }
    else
    {
    }
  }
}
Quuxplusone commented 9 years ago

Repros with

echo 'void f(){for(;;){if(a){}else{}}}' |./bin/clang-format -style='{"BasedOnStyle": "LLVM", "BreakBeforeBraces": "Allman", "AllowShortBlocksOnASingleLine" : "true", "AllowShortIfStatementsOnASingleLine" : "true", "AllowShortLoopsOnASingleLine" : "true"}'

Quuxplusone commented 5 years ago
I realize this is a very old issue, but incase anyone is listening were you
concerned about the "if"?

Surely this comes from the AllowShortBlocksOnASingleLine, are you expecting the
"Allman" setting to override this?

Just trying to assess if this is something we still need to consider?

MyDeveloperDay

$ echo 'void f(){for(;;){if(a){}else{}}}' |./bin/clang-format -
style='{"BasedOnStyle": "LLVM", "BreakBeforeBraces": "Allman",
"AllowShortBlocksOnASingleLine" : "true", "AllowShortIfStatementsOnASingleLine"
: "true", "AllowShortLoopsOnASingleLine" : "true"}'
void f()
{
  for (;;)
  {
    if (a) {}
    else
    {
    }
  }
}

vs

$ echo 'void f(){for(;;){if(a){}else{}}}' |./bin/clang-format -
style='{"BasedOnStyle": "LLVM", "BreakBeforeBraces": "Allman",
"AllowShortBlocksOnASingleLine" : "false",
"AllowShortIfStatementsOnASingleLine" : "true", "AllowShortLoopsOnASingleLine"
: "true"}'
void f()
{
  for (;;)
  {
    if (a)
    {
    }
    else
    {
    }
  }
}