Issue 97242
Summary [clang-format] bad formatting of entire constructor definition when first member initializer uses trailing comma
Labels clang-format
Assignees
Reporter jacobsa
    When the first element of a constructor's member initializer list is initialized with braces and uses a trailing comma, clang-format won't format the constructor definition at all. For example, it leaves this bad formatting as-is:

```c++
MyClass::MyClass()
    :foo_{MakeFoo(),}, bar_{MakeBar(),}, baz_{MakeBaz(),        }{}
```

It's only the first element though. If you change that one to use parens, it formats the entire definition well, including the other initializers that use trailing commas:

```c++
// Before
MyClass::MyClass()
 :foo_(MakeFoo()), bar_{MakeBar(),}, baz_{MakeBaz(),        }{}

// After
MyClass::MyClass()
    : foo_(MakeFoo()),
      bar_{
 MakeBar(),
      },
      baz_{
          MakeBaz(),
      } {}
```

I would hope that the original example would be formatted similarly, even with the trailing comma in the first initializer:

```c++
// Desired outoput
MyClass::MyClass()
 : foo_{
          MakeFoo(),
      },
      bar_{
 MakeBar(),
      },
      baz_{
          MakeBaz(),
      } {}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to