<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102268>102268</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format "BraceWrapping.AfterControlStatement: Always" causes break before "break"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
detly
</td>
</tr>
</table>
<pre>
Consider this source:
```c
int do_thing(int magic)
{
switch (magic)
{
case 0:
{
if (0)
{
return 0;
}
else
{
return 1;
}
} break;
}
return 0;
}
```
...and this `.clang-format`:
```yaml
BasedOnStyle: WebKit
Language: Cpp
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterControlStatement: Always
AfterFunction: true
BeforeElse: true
IndentCaseLabels: true
IndentCaseBlocks: false
```
Running `clang-format` puts the `break` on a new line:
```c
int do_thing(int magic)
{
switch (magic)
{
case 0:
{
if (0)
{
return 0;
}
else
{
return 1;
}
}
break;
}
return 0;
}
```
If, on the other hand, I remove the `AfterControlStatement: Always` option, the `break` stays where it is, but the braces after the `if` statements are now put on the same line as the `if`:
```c
int do_thing(int magic)
{
switch (magic) {
case 0:
{
if (0) {
return 0;
}
else {
return 1;
}
} break;
}
return 0;
}
```
This is confusing to me, because I would expect it to not affect a brace _before_ the `break` control statement, since it only concerns breaking _after_ control statements. There seems to be no combination of `BraceWrapping` options that preserves the original code.
Tested with `clang-format` 18 and 19, on Ubuntu 24.04.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lsFu4zgPx5_GuRA1ZDl10oMPTfsFKL4BFtiZxRwLWaZt7chSINHN5u0XtJOmnmS3A8x0jSJNyD9pWvxRsorRtA6xTG43ye3jQg3U-VDWSPawqHx9KB-8i6bGANSZCNEPQWOS3yfiMRGnz0JMf3r6bRxB7Z-pM65N5Jp_9qo1OpF3x4DVZvoCABD3hnQHiVzPReybCfnSK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