Skip to content

[clang-format] Regression in BraceWrapping after else block with AllowShortBlocksOnASingleLine and AllowShortIfStatementsOnASingleLine #160775

@shyun3

Description

@shyun3

.clang-format:

AllowShortBlocksOnASingleLine: Always
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
BraceWrapping:
  AfterControlStatement: Always
  BeforeElse: true
BreakBeforeBraces: Custom

test.cpp:

int main() {
  int x = 1;
  if (x > 0)
  {
    ++x;
    --x;
  }
  else
  {
    --x;
    ++x;
  }
}

Expected result of running clang-format: no change

Actual result:

int main() {
  int x = 1;
  if (x > 0)
  {
    ++x;
    --x;
  }
  else {
    --x;
    ++x;
  }
}

Note how the brace after the else on line 8 has not been wrapped despite the block not being "short".

This seems to occur beginning at version 21.1.0. Version 20.1.8 yields the expected result.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions