Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

BraceWrapping.AfterControlStatement: MultiLine breaks AllowShortXXXX settings #51565

Open Quuxplusone opened 2 years ago

Quuxplusone commented 2 years ago
Bugzilla Link PR52598
Status NEW
Importance P normal
Reported by Kyrylo Bohdanenko (kyrylo.bohdanenko@gmail.com)
Reported on 2021-11-24 08:07:09 -0800
Last modified on 2021-11-24 08:07:55 -0800
Version 13.0
Hardware PC Linux
CC djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Consider the following code (file.cpp)

void test() {
  if (true) return;
  if (true) { return; }

  while (true) return;
  while (true) { return; }
}

And the following configuration (.clang-format):

Language: Cpp
BreakBeforeBraces: Custom
BraceWrapping:
  AfterControlStatement: MultiLine
AllowShortBlocksOnASingleLine: Always
AllowShortLoopsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse

Run clang-format as follows:

clang-format -style=file file.cpp

Produces:

void test() {
  if (true) return;
  if (true) {
    return;
  }

  while (true) return;
  while (true) {
    return;
  }
}

Expected output: same as input.

Changing AfterControlStatement to Never or Always will produce the expected
output. It looks like AfterControlStatement:MultiLine does not respect
AllowShortBlocksOnASingleLine setting.
Quuxplusone commented 2 years ago

Additional information can be found in https://bugs.llvm.org/show_bug.cgi?id=47936 (and any code reviews attached to it)