Skip to content

clang-format with BlockIndent and ContinuationIndentWidth < 4 not working for if statements #80123

@JoElfner

Description

@JoElfner

Description

When using clang-format v18.0 with the following minimum config:

---
AlignAfterOpenBracket: BlockIndent
IndentWidth: 2
ContinuationIndentWidth: 2
ColumnLimit: 80

Breaking if-statements which are longer than the column limit won't work. I found out, that BlockIndent seems to be broken for if-statements when ContinuationIndentWidth < 4.

Seems to be (slightly) related to: #28052

Input

And I try to format the following if statement:

if ( name== "ABCDE" || name == "ASDASD" || name == "asldmald" || name == "someverylong" || name == "break this" || name == "abcde") {
  callthismethod();
    alsoassignthis = 24;
}

Current output

clang-format correctly formats everything except for breaking the if statement with BlockIndent:

if (name == "ABCDE" || name == "ASDASD" || name == "asldmald" || name == "someverylong" || name == "break this" || name == "abcde") {
  callthismethod();
  alsoassignthis = 24;
}

Expected output:

if (
  name == "ABCDE" || name == "ASDASD" || name == "asldmald" 
  || name == "someverylong" || name == "break this" || name == "abcde"
) {
  callthismethod();
  alsoassignthis = 24;
}

Comment: I don't mind where the || operators go, even though I'd prefer the math-style of breaking before it.

Any way to achieve this?

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