<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80049>80049</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] AlignAfterOpenBracket tries to do too much and doesn't do what it says
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
`AlignAfterOpenBracket` has four configuration values:
* `Align`
* `DontAlign`
* `AlwaysBreak`
* `BlockIndent`
This configuration option is trying to accomplish the following separate goals, assuming you need to insert a line break between arguments:
1. Do you use one indentation level or do you align to the opening bracket? (`Align` vs `DontAlign`)
2. Do you start the first argument on the same line as the open bracket or the next line? (`AlwaysBreak` vs others)
3. Do you put the closing bracket on the same line as the last argument or a new line? (`BlockIndent` vs others)
My style (and one I've seen other people use) is to always put a new argument on each line, with one level of indentation, and have the closing bracket on its own line (I think I've seen this indented or not? I prefer not), by analogy to curly braces `{}`:
```cpp
function(
x,
y,
z
);
```
The behavior of `BlockIndent` also does not match the documentation. The documentation states:
> `BAS_BlockIndent` (in configuration: `BlockIndent`) Always break after an open bracket, if the parameters don’t fit on a single line. Closing brackets will be placed on a new line.
However, given
```cpp
using type = std::remove_cv_t<
add_common_cv_reference<
std::common_type_t<std::decay_t<T0>, std::decay_t<T1>>,
T0,
T1
>
>;
```
and `AlignAfterOpenBracket set to `BlockIndent`, clang-format turns that into
```cpp
using type = std::remove_cv_t<
add_common_cv_reference<
std::common_type_t<std::decay_t<T0>, std::decay_t<T1>>,
T0,
T1>>;
```
It's also unclear whether `BlockIndent` is supposed to do alignment or indentation, but in my code it looks like it inconsistently does both? `AlwaysBreak` is similarly ambiguous in its documentation.
To summarize, my preferred resolution of this issue is that we would have something like:
`AlignWithOpenBracket`: `true` is behavior of current `Align`, `false` is behavior of current `DontAlign`: this option controls only whether new arguments are aligned to be right after the open bracket if they don't fit on the first line.
```cpp
// true
function(a,
b,
c);
```
vs
```cpp
// false
function(a,
b,
c);
```
`BreakAfterOpenBracket`: `true` means that if arguments don't all fit on one line, the first argument starts on a new line, `false` means the first one goes on the same line as the open bracket.
```cpp
// true
function(
a,
b,
c);
```
vs
```cpp
// false
function(a,
b,
c);
```
`BreakBeforeCloseBracket`: `true` means that means that if arguments don't all fit on one line, the closing bracket starts a new line, `false` means it goes on the same line as the final argument.
```cpp
// true
function(
a,
b,
c
);
```
vs
```cpp
// false
function(
a,
b,
c);
```
So for me to get my preferred formatting, I would have
```
AlignWithOpenBracket: false
BreakAfterOpenBracket: true
BreakBeforeCloseBracket: true
```
It is not clear to me what any of the four current options correspond to exactly in this system, based on documentation and current behavior.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWE1v4zgS_TX0pdCGLNmxdfDBiTvYHBZ7mAb22KCoksQNxRJIym7Nr1-QlB3JcZLBDBa7wDYacsSv-njF98rm1spaI-7Z5pFtjgveu4bMvuQnWVpHGhcFlcOePSQHJWt9qByaf3SoHw0Xr-jYQwINt1BRb0CQrmTdG-4kaThx1aNl2YElR5YcWHqAyynsIZkNHkm7uxMHdeaDfTTIX2-nHhWJ1xddonZvU-H5o5H2xhfqwoe04MwgdQ2OgAtBbaekbcA1CBUpRWc_Z7HjhjuEmriyLH0Cbm3f-qmBetCIpd8vtUXjgIOSGqHwPkKB7oyogZu6b1G7t_BXSzhS2N9bBNIIMvge_VN4QgVkoIxruE-GN-I9ow61N16MKc-egaW7SS7hZN9lMc2j3fRq1zpuXAxVGuuuPgLpMGp5izEWbq92L0a9b35M4y8XFk29mGLkfSHXoLFXF7KrC10fHRCK7CSiDz1QfOanAQ4azzf254Vwx358_n0A6waFfhfXZYDghaXbE4L1kIVN0CF1Cj1GLM1DvRDwEGBwPtqfZg65aKJD6ROcpWvCwSOe1RTkUEi6hIaf8KMsSGeBzjomgaW7F3CN1K8zR50v73gulj4pmkJNvEBnsML4nubeXDEA11xR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