Issue 178110
Summary [clang-format] comment in brace-enclosed initializer in member initializer list of constructor is misformatted
Labels clang-format
Assignees
Reporter joelhock
    clang-format version 21.1.0-rc3 (41cf77340de) simply stopped formatting when encountering C++ code like:
```
MyClass::MyClass(): aField        {
  // a comment causing nothing to get formatted in 21.1.0-rc3 41cf77340de
          },
 here(1),
                       orThere(2),
      orAnywhere(3) {
}
```

clang-format version 22.1.0-rc1 (8164f1a) does not fall over completely anymore, but it does fail to correctly format the comment if the brace-enclosed initializer is not empty (note `//` does not have a preceding space like it should):
```
MyClass::MyClass()
    : aField{// comment is odd with a value in parens in 22.1.0-rc1 8164f1a
             5},
 here(1), orThere(2), orAnywhere(3) {}
```
having an empty initializer looks fine, though:
``` 
MyClass::MyClass()
    : aField{
          // comment is fine with empty initializer in 22.1.0-rc1 8164f1a
      },
 here(1), orThere(2), orAnywhere(3) {}
```
as does using parentheses:
```
MyClass::MyClass()
    : aField( // comment is fine with a value in parens in 22.1.0-rc1 8164f1a
          5),
      here(1), orThere(2), orAnywhere(3) {}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to