Issue 52913
Summary Indent-level regression for AlignConsecutiveAssignments in clang-format 13.0.0, works in clang-format 12.0.1
Labels new issue
Assignees
Reporter JohnC32
    The following file.cpp is  indented using clang-format 12.0.1:

```c++
namespace data_manager {
class Value {
  public:
    Value(int a, int b, int c, int d, int e, const double* f);
};
}  // namespace data_manager

enum {
    foobar12345,
    foobar12345678901234,
    foobar123456789012345,
    foobar123456789012345678901,
    foobar123456789012345678901234567890
};

void foo() {
    const double              val_data_k[] = {280};
    const data_manager::Value val_k        = data_manager::Value(
        foobar12345, foobar123456789012345678901234567890, foobar123456789012345,
        foobar12345678901234, foobar123456789012345678901, val_data_k);
}
```

If I run clang-format 13.0.0 on this the indent-level for the arguments to the data_manager::Value constructor are incorrect. They should be indented by 4 spaces relative to the prior statement but are indented by 12 spaces. Generally, the indent level for arguments seems to randomly vary with clang-format 13 whereas with clang-format 12.0.1 it's consistently 4 spaces relative to the prior statement.

```c++
namespace data_manager {
class Value {
  public:
    Value(int a, int b, int c, int d, int e, const double* f);
};
}  // namespace data_manager

enum {
    foobar12345,
    foobar12345678901234,
    foobar123456789012345,
    foobar123456789012345678901,
    foobar123456789012345678901234567890
};

void foo() {
    const double              val_data_k[] = {280};
    const data_manager::Value val_k        = data_manager::Value(
               foobar12345, foobar123456789012345678901234567890, foobar123456789012345,
               foobar12345678901234, foobar123456789012345678901, val_data_k);
}
```

Here's the _clang-format used in the above:

```yaml
---
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 4
AccessModifierOffset: -2
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
CompactNamespaces: true
...
```
If you comment out the AlignConsecutiveAssignments, then clang-format 12.0.1 and 13.0.0 are both correct.

As a workaround for clang-format 13.0.0, if you introduce a comment after the open parenthesis, the indent-level is correct:

```c++
    const data_manager::Value val_k        = data_manager::Value(  //
        foobar12345, foobar123456789012345678901234567890, foobar123456789012345,
        foobar12345678901234, foobar123456789012345678901, val_data_k);
```
However, it's not practical to update large number of files that have been adversely impacted by this.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to