llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] `BreakAfterOpenBracketIf` has no effect when function call inside `if` statement is preceded by an unary operator

Open arthur-cornfield opened this issue 4 months ago • 2 comments

.clang-format:

ContinuationIndentWidth: 2
BinPackArguments: false
BreakAfterOpenBracketIf: true
BreakBeforeCloseBracketIf: true

C++ file:

#include <cstdio>

int main() {
  if (!printf("%s %s %s %s %s %s", "foobar", "foobar", "foobar", "foobar", "foobar", "foobar")) {
    return 1;
  }
}

Expected formatting:

#include <cstdio>

int main() {
  if (
    !printf("%s %s %s %s %s %s",
           "foobar",
           "foobar",
           "foobar",
           "foobar",
           "foobar",
           "foobar")
  ) {
    return 1;
  }
}

Actual formatting:

#include <cstdio>

int main() {
  if (!printf("%s %s %s %s %s %s",
              "foobar",
              "foobar",
              "foobar",
              "foobar",
              "foobar",
              "foobar")) {
    return 1;
  }
}

Using == false check after printf call instead of ! unary operator results in the correct formatting.


clang-format version is 22.1.8

arthur-cornfield avatar Jul 27 '26 09:07 arthur-cornfield

@llvm/issue-subscribers-clang-format

Author: arthur-cornfield

.clang-format: ```yaml ContinuationIndentWidth: 2 BinPackArguments: false BreakAfterOpenBracketIf: true BreakBeforeCloseBracketIf: true ```

C++ file:

#include &lt;cstdio&gt;

int main() {
  if (!printf("%s %s %s %s %s %s", "foobar", "foobar", "foobar", "foobar", "foobar", "foobar")) {
    return 1;
  }
}

Expected formatting:

#include &lt;cstdio&gt;

int main() {
  if (
    !printf("%s %s %s %s %s %s",
           "foobar",
           "foobar",
           "foobar",
           "foobar",
           "foobar",
           "foobar")
  ) {
    return 1;
  }
}

Actual formatting:

#include &lt;cstdio&gt;

int main() {
  if (!printf("%s %s %s %s %s %s",
              "foobar",
              "foobar",
              "foobar",
              "foobar",
              "foobar",
              "foobar")) {
    return 1;
  }
}

Using == false check after printf call instead of ! unary operator results in the correct formatting.


clang-format version is 22.1.8

Can I be assigned on this? I have a pull request that will resolve this issue.

johnnyb2543 avatar Aug 08 '26 23:08 johnnyb2543