<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59235>59235</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format misattributes expression annotations to braceless control flow statement
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rymiel
</td>
</tr>
</table>
<pre>
Style used: `{}` (default)
Input and expected result
```cpp
for (auto i : j)
[[maybe_unused]] i;
if (x)
[[maybe_unused]] x;
```
Actual output with clang-format 15 and 16 (c0414518f1d9132895e317d556cecd292d8edda0)
```cpp
for (auto i : j) [[maybe_unused]]
i;
if (x) [[maybe_unused]]
x;
```
Output with clang-format 13
```cpp
for (auto i : j)
[[maybe_unused]] i;
if (x) [[maybe_unused]]
x;
```
Note that when using `ColumnLimit: 0`, clang-format will instead see the annotation as being used with a continuation indent, producing this (with 15, 16):
```cpp
for (auto i : j)
[[maybe_unused]]
i;
if (x)
[[maybe_unused]]
x;
```
I've yet to familiarize myself with the attribute grammar to know if there's an ambiguity here (i.e. we need to potentially add a special case for things like `maybe_unused`) or if annotations can't go after brace-less control flow statements.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VE1vnDAQ_TVwGWUF5mPhwGGTqFKkqj30B1TGHlgnxl7ZJhv66ztmlWRz2G6qSpUswHjmzZs3T-6tXLofYdEIs0eZFDtI6izZ3ibbe_qAhDUSBz7rkLA2ye6TbHd6PpjDHIAbCfhyQBFQgkMf405BBLIucTic_gzWRTQ-BwsKYqHHN0iApLqlNfGlx5-zWalU97RAJcXteV01RJSXz6S-vKe-sjlH2okwcw12DrGTowp7EJqb8YaYTjxAXq3t5XUsKLIyL6u8GXLZ5gVr2gqLfCurqhYoJGuZbFBKnr2r9EkBLtJ_be-yAFdTrwjw_WLnxX8b4r_28M0GhLAn0sc9GvKwMmN08J3V82S-qkmFyHJNY3cf2zwqrUEZH5BL8BhxkEZubOBBWQPcQ48RL7I6ycRBWBOUmU8Rykg0IQIfnJWziMFhr3zsbo3Pq3iY11GkYndO_G-1vazudaN8HuOK2g8J2z4jLBiASA58Ulpxp34hTItHPZxEWmUMwal-puGMjk8TdzHhydgjEC0KcEhQntQGPvVqnFVYIP6NlNUGN3BEMEiyU9qBZkyic60X4FLSEDzdOLQHwT1C1I1EN6MHrZ4wTv9Dg3HyLVAQVX6frqdkQxwCjBb4ENBB77jAG43er1N2VsOgibGnDJyIgt-k2OV13dYVq8omlV0h26LlaVBBY_fBXJPybxr4eEfS7ehXV51RoObWon-omc5Od_sQDj4aiH2hNZLIc78RdqKN1s-vrxsy4SNdxbRV3s_o6aNqWVGl-461WzlUpahKKUXJRLatq7LNOSuwaVvZppr3qH0XDcLYeSe0JYOkqmMZY3nOmrxmjDWbbZHlbJBVX3Mh-DAkZYYTV3oTqWysG1PXraz6efR0qJUnAd8OOakx0oTXioRPtt9b17llUqjTlX-3kv8NCk775A">