<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57108>57108</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-format: AlignAfterOpenBracket: AlwaysBreak not having an effect on braced blocks results in annoying formatting of requires expressions in concept definitions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          griwes
      </td>
    </tr>
</table>

<pre>
    Consider the following snippet:

```cpp
template<typename T>
concept foo = true;

template<typename T>
concept bar = foo<T> && requires (T t) { { t.some_very_long_function_call_goes_here(1,2,3,4,5)} -> foo; };
```

I have a config with a 110 column limit, 4 space indent, and `AlignAfterOpenBracket: AlwaysBreak`. The result of formatting the above should be something like this:

```cpp
template<typename T>
concept foo = true;

template<typename T>
concept bar = foo<T> && requires(T t) {
    { t.some_very_long_function_call_goes_here(1, 2, 3, 4, 5) } -> foo;
};
```

However, clang-format-15 turns it into the following:

```cpp
template<typename T>
concept foo = true;

template<typename T>
concept bar = foo<T> && requires(T t) {
                            {
                                t.some_very_long_function_call_goes_here(1, 2, 3, 4, 5)
                                } -> foo;
                        };
```

This is broken in two ways, but, surprisingly, the wild placement of the braces doesn't actually annoy me that much; arguably, there is a sane coding style to find there if the closing brace was aligned with the opening brace around the atomic constraint.

The alignment of the whole block, though, is _really_ bad. clang-format also ignores this config flag when formatting lambdas in subexpressions, but that is a much more minor annoyance IMHO; yanking a lambda out into a variable when we get to this behavior arguably results in cleaner code. The same cannot, however, be said about concepts, because concepts can only be placed at a namespace scope, so factoring a requires expression out pollutes that namespace with symbols that aren't a part of the interface.

And yes, I am aware that the docs do say that the option doesn't apply to braces, but that is in fact the bug here. Though if there's desire to not have this option change the behavior of braced blocks like this, I'd be happy to get a separate option to control this.


I would be happy to make an attempt at a solution for this, but quick searching through the codebase for the use of the config flag didn't help me with understanding of what would need to happen for this option to become correctly accepted for these cases, so if someone is able to give me a pointers on where to start, maybe I can fix this myself.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVsmO2zgQ_Rr5QrRhy1v74EMvE6QPg1z6blBUWeKYEjUk1Y7-fl6R8hZkkmAwlxiSbYlkLe9VPbKw5bB7sa3XJTkRahIHa4w96bYSvtVdRyFbPGWz12x2_l7P0qW6Lr0J1HRGBsoWL2HoqJUNifds8UcaVbZV1AXYtSJbvIrgesx8vjX5awYK6aIBGMJEHhdZvsYlHP3da0cez4_vImT5VmSb53iHqbcN7T_IDXtj22p_6FsVtG33Shqzryz5fU2OsHKe5S857gXuJe4V7GSbV_HAnqJTNvl6jf0MxG0qb6KWHySkQNQHXYmTDjWe5vMZ3pi-aYXRjUaIL2IpfCcVCd2W1MY3si0F7D0ZXbVPh0DuC8B4dlIdIwviyZzk4J8dySOmTcU76ELavQnCHhCia2QIzBzzKAuLQHxte1OKAv-AQ6h51OgjYYr2vw-zd8SmxQKf_8CwYIrFIhLAX6tk9I7mMYOfcf3Znghu2Yoysq0eEgMP85UIvWu90AHkBnvfVr896P_2-aVJ_PkfGPs1R9-l9QeTf0z3OzpG4CqcPVILZkU4WcEdyVEVfWxh37vOaQ-ezcDPTP1JowPBiKIGjc6tym8L9DUkq0S2bZZvgpAq9Mh_gAy0dhAN96gMoulVzdIjXdXL4mLVEccihZctQVrKKNhhMFhlxQGacp6UvCljOajkFUFjKasMlUmheIpFqVynSGf7ZETIYButWNF8cBIVPb2HhZKt2-ROtUUkhbHqmOK1fVXzP8S8h34hzT0qsJzedQ7seCtgyrKYs0KdZfRgJLS0Buw3KmdkU5TIBEz4vqCvHVZ5lNGZj4RfRIlBFA3MikbDeoJYohHE25-fvzC8eDqyUTmaFbYfu1eKD-k0oKcUwYlERUHEvuZyICi-ZpsjQaMkx7iUIfDjmCBKeu25GxX7j_VSXzWENVrqkoUbrsc2TbmQkr2nyzteL2wLV1gTCwurgJ7gVk-bileg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