[all-commits] [llvm/llvm-project] c18349: [clang-format] Recognize more braced initializers ...

sstwcw via All-commits all-commits at lists.llvm.org
Mon Apr 27 07:53:47 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c183492e609b57b4181de6c3f15c897f78d13ace
      https://github.com/llvm/llvm-project/commit/c183492e609b57b4181de6c3f15c897f78d13ace
  Author: sstwcw <su3e8a96kzlver at posteo.net>
  Date:   2026-04-27 (Mon, 27 Apr 2026)

  Changed paths:
    M clang/lib/Format/UnwrappedLineParser.cpp
    M clang/unittests/Format/FormatTest.cpp
    M clang/unittests/Format/FormatTestComments.cpp
    M clang/unittests/Format/TokenAnnotatorTest.cpp

  Log Message:
  -----------
  [clang-format] Recognize more braced initializers (#192299)

new

```C++
a = {x * x, x * x};
```

old

```C++
a = {x * x, x *x};
```

Fixes #57442.

The patch makes the program treat a brace following an equal sign a
braced initializer.

The patch changes these tests.

- In UnderstandsSingleLineComments and CommentsInStaticInitializers, the
  comment in the formatted code used to be on a separate line, now it is
  on the same line as the brace.  The new behavior is consistent with
  comment in braced lists that are correctly identified.  Here is the
  code for it from the test LayoutCxx11BraceInitializers and the
  function mustBreakBefore.

  ```C++
  // In braced lists, the first comment is always assumed to belong to the
  // first element. Thus, it can be moved to the next or previous line as
  // appropriate.
  verifyFormat("function({// First element:\n"
               "          1,\n"
               "          // Second element:\n"
               "          2});",
               "function({\n"
               "    // First element:\n"
               "    1,\n"
               "    // Second element:\n"
               "    2});");

  if (Right.is(tok::comment)) {
    return Left.isNoneOf(BK_BracedInit, TT_CtorInitializerColon) &&
           Right.NewlinesBefore > 0 && Right.HasUnescapedNewline;
  }
  ```

- In FormatsBracedListsInColumnLayout, the style is configured to one
  which allows a trailing comment in the first line.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list