Skip to content

BraceWrapping.AfterControlStatement: MultiLine breaks AllowShortXXXX settings #51940

@elvenfighter

Description

@elvenfighter
Bugzilla Link 52598
Version 13.0
OS Linux

Extended Description

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.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions