Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JoElfner opened this issue Jan 31, 2024 · 1 comment · May be fixed by #108332
Open

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

JoElfner opened this issue Jan 31, 2024 · 1 comment · May be fixed by #108332

Comments

@JoElfner
Copy link

JoElfner commented Jan 31, 2024

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?

@flyx
Copy link

flyx commented Feb 7, 2024

Related to #79176 which aims for the same formatting, while describing current behavior for ContinuationIndentWidth = 4.

@gedare gedare linked a pull request Sep 12, 2024 that will close this issue
gedare added a commit to gedare/llvm-project that referenced this issue Sep 23, 2024
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Oct 18, 2024
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Dec 2, 2024
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Jan 28, 2025
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Jan 29, 2025
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Feb 9, 2025
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue Apr 30, 2025
Introduce new style option to allow overriding the breaking after the
opening parenthesis for control statements (if/for/while/switch).

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue May 1, 2025
Introduce new style option to allow overriding the breaking after the
opening parenthesis for control statements (if/for/while/switch).

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue May 12, 2025
Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
gedare added a commit to gedare/llvm-project that referenced this issue May 22, 2025
Introduce new style option to allow overriding the breaking after the
opening parenthesis for control statements (if/for/while/switch).

Fixes llvm#67738.
Fixes llvm#79176.
Fixes llvm#80123.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants