[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 13 10:10:11 PST 2025


leijurv wrote:

Oh gosh, that's embarrassing. It looks like I was so focused on the column limit that I didn't cover cases where the column limit doesn't break the template fully. In other words, I would just type "Fooooooooooooooooooooooo" and force it onto the next line, without noticing that a slightly shorter Foooooo would have different behavior, I apologize.

In your example, I see that `BreakBeforeTemplateCloser: Multiline, ColumnLimit: 17` gives me:

```
template <
    class A,
    class B
>
class C {
  void f() {}
};
```

But `BreakBeforeTemplateCloser: Multiline, ColumnLimit: 18` gives me:

```
template <class A,
          class B>
class C {
  void f() {}
};
```

It looks to me like the problem is that when writing this code originally, I searched through the codebase for `FormatStyle::BAS_BlockIndent` and tried to replicate it. This causes the behavior here, where the `>` only goes onto the next line if there was a break after the matching `<`.

In other words, it seems **I was wrong** when I said `I didn't really have an intent in mind between your described options of BlockIndent vs Multiline but yes, I suppose what I have here is Multiline.` Actually, it seems like what I have here is BlockIndent.

So, thankfully I think I can fix this just by **renaming my option from Multiline to BlockIndent**, per your comment [here](https://github.com/llvm/llvm-project/pull/118046#discussion_r1912382882).

Additionally I have **added more tests** to cover this case where the first parameter can fit within the ColumnLimit on the same line as the `template <`.

https://github.com/llvm/llvm-project/pull/118046/commits/09528826ffc9f7b783d043c4447419cfd9a6ff38

https://github.com/llvm/llvm-project/pull/118046


More information about the cfe-commits mailing list