Issue 136369
Summary [clang-format] AlignAfterOpenBracket and Cpp11BracedListStyle option combination leads to inconsistent formatting
Labels clang-format
Assignees
Reporter mrizaln
    Given a C++ file with following content

```cpp
struct S {
  int a;
  int b;
};

int aaa(S s);
int bbbb(S s);

namespace f {
int a(S s);
int bb(S s);
} // namespace f

int main() {
  auto a = S{ 1, 2 };
  aaa({ 1, 2 });
  bbbb({ 1, 2 });
  f::a({ 1, 2 });
  f::bb({ 1, 2 });

  aaa({
 1,
      2,
  });

  auto i = aaa({
      .a = 1,
      .b = 2,
 });

  bbbb({
      1,
      2,
  });

  auto j = bbbb({
      .a = 1,
      .b = 2,
  });

  f::a({
      1,
      2,
  });

  auto k = f::a({
      .a = 1,
      .b = 2,
  });

  f::bb({
      1,
 2,
  });

  auto l = f::bb({
      .a = 1,
      .b = 2,
 });
}
```

when it is formatted using clang-format (20.1.2) with the following config file,

```yml
AlignAfterOpenBracket: BlockIndent
Cpp11BracedListStyle: false
```

the result of the formatting is inconsistent:

```cpp
struct S {
  int a;
  int b;
};

int aaa(S s);
int bbbb(S s);

namespace f {
int a(S s);
int bb(S s);
} // namespace f

int main() {
  auto a = S{ 1, 2 };
  aaa({ 1, 2 });
 bbbb({ 1, 2 });
  f::a({ 1, 2 });
  f::bb({ 1, 2 });

  aaa({
      1,
 2,
  });

  auto i =
      aaa({
          .a = 1,
          .b = 2,
      });

  bbbb(
      {
          1,
          2,
      }
 );

  auto j = bbbb(
      {
          .a = 1,
          .b = 2,
 }
  );

  f::a(
      {
          1,
          2,
      }
  );

 auto k = f::a(
      {
          .a = 1,
          .b = 2,
      }
 );

  f::bb(
      {
          1,
          2,
      }
  );

  auto l = f::bb(
      {
          .a = 1,
          .b = 2,
      }
 );
}
```

The bug only happen specifically when setting `AlignAfterOpenBracket` to `BlockIndent` and `Cpp11BracedListStyle` to false, also happen when setting `AlignAfterOpenBracket` to `AlwaysBreak` and `Cpp11BracedListStyle` to false, though the result is different:

```cpp
struct S {
  int a;
  int b;
};

int aa(S s);
int bbbb(S s);

namespace f {
int a(S s);
int bb(S s);
} // namespace f

int main() {
  auto a = S{ 1, 2 };
  aa({ 1, 2 });
  bbbb({ 1, 2 });
  f::a({ 1, 2 });
  f::bb({ 1, 2 });

  aa({
      1,
      2,
 });

  auto i =
      aa({
          .a = 1,
          .b = 2,
 });

  bbbb(
      {
          1,
          2,
      });

  auto j = bbbb(
      {
          .a = 1,
          .b = 2,
      });

  f::a(
 {
          1,
          2,
      });

  auto k = f::a(
      {
 .a = 1,
          .b = 2,
      });

  f::bb(
      {
 1,
          2,
      });

  auto l = f::bb(
      {
          .a = 1,
          .b = 2,
      });
}
```

The expected result should be the same as the input.
Tested on clang-format 20.1.2 (Fedora 20.1.2-3.fc42)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to