Skip to content

[clang-format] if-else single line block formatting wrong on clang-format-21 (inconsistent with version 20) #162552

@ankurvdev

Description

@ankurvdev

The clang-format

BreakBeforeBraces: Custom
# if true this allows if (a) { return; } to be put on a single line.
AllowShortBlocksOnASingleLine: Always
# If true, if (a) return; can be put on a single line.
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
BraceWrapping:
  AfterControlStatement: Always
  BeforeElse: true

produces different result on clang-format-20 vs clang-format-21 and the version 21 appears to be incorrect.
It appears that the AfterControlStatement: Always is ignored in clang-format-21

The else block below has a different in brace-wrapping

// with clang-format-20
int foo() {
  int bar = 0;
  int verylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongvar;
  if (bar) { return bar; }
  else 
  {
    return verylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongvar;
  }
}
// with clang-format-21
int foo() {
  int bar = 0;
  int verylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongvar;
  if (bar) { return bar; }
  else {
    return verylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongvar;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions