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

    <tr>
        <th>Summary</th>
        <td>
            clang-format: misformatted function declarator when using multiple requires-expressions in and a trailing return-type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    `clang-format` seems to get confused when formatting a constrained function template, which has multiple joined requires-expressions and uses a trailing return-type syntax.

Consider this example:

```c++
template<typename T>
requires std::floating_point<T>
auto do_stuff(T t) -> int
{
    do_more_stuff(t);
    return 0; 
}

template<typename T>
requires std::floating_point<T> || std::integral<T>
auto do_stuff2(T t) -> int
{
    do_more_stuff(t);
    return 0; 
}

template<typename T>
requires (std::floating_point<T> || std::integral<T>)
auto do_stuff3(T t) -> int
{
    do_more_stuff(t);
    return 0; 
}

template<typename T>
auto do_stuff4(T t) -> int
requires std::floating_point<T> || std::integral<T>
{
    do_more_stuff(t);
    return 0; 
}

template<typename T>
requires std::floating_point<T> || std::integral<T>
int do_stuff5(T t)
{
    do_more_stuff(t);
    return 0; 
}
```

After formatting it with `clang-format` - no config file, just `--style="{BasedOnStyle: llvm, AlwaysBreakAfterReturnType: All}"` - the result looks as follows:

```c++
// OK
template <typename T>
  requires std::floating_point<T>
auto
do_stuff(T t) -> int {
  do_more_stuff(t);
  return 0;
}

// Not OK
template <typename T>
  requires std::floating_point<T> || std::integral<T>
                                   auto
                                   do_stuff2(T t) -> int {
  do_more_stuff(t);
  return 0;
}

// Not OK - "auto" should be followed by a new line
template <typename T>
  requires(std::floating_point<T> || std::integral<T>)
auto do_stuff3(T t) -> int {
  do_more_stuff(t);
  return 0;
}

// OK
template <typename T>
auto
do_stuff4(T t) -> int
  requires std::floating_point<T> || std::integral<T>
{
  do_more_stuff(t);
  return 0;
}

// OK
template <typename T>
  requires std::floating_point<T> || std::integral<T>
int
do_stuff5(T t) {
  do_more_stuff(t);
  return 0;
}
``` 

Tested version:
```
clang-format version 15.0.0 (https://github.com/llvm/llvm-project.git 1f69f7ea9af4bd4e8001a25044aa026557f366f7)
```

Platform:
```
Arch Linux, x86_64
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV01v4zYQ_TXyZWBDpr7sgw5O0lxadBe7uQe0NJKYpUiXpGL73-9Qim2lsbsJ6rZbQ7Ak8pF8bzh4I651uc-DNCwkV_W00qbljl7BIrYWnIYaHRRaVZ3FErYNKhhATqgauO-yznChqLfqVOGEVuCw3UjuMGC3NEQUDTTcQttJJzYS4Un3cIN_dMKgneJuQzdLIy1wVQItRQ_gp5V-FYOuM2rq9hsEu1eO72ZBeBeEq-H_lsaJEg24RljAHafFMYhWYwxJGq4iYDf-6luPPKNbP7niLcJDEP0y9B74gXWlny5aVVJzr_txQwocjTqBeUexKvWjdV1VBWzxAC5gS5gSADx2YJG9LAz0I3CrDR5HeHwQjQCDbAipEQ7j78airkIfguyWrhOKurA2XF6Wx34ufTT335RIxN6qjH4Kla8oxZcoXXWv_79ZSo3HWCXHWF1b1cFKxiJXlSMDGjmjcLAVroEz1joFpXtLFTVUQvYu-dRZ57HTqXV77153AWNE-YaT7X5SX4fGFUj53Hr8Sm753t4Y5N_6pb_0fB8ovh61ktLTpRn65VyDJMiS_YLU-ht5qyWqUuqtfZdNBuyeLvj06-sNhfM7CvBh4xyeLrsnjDbvB1s32riz2fii5Xftrq7nfTkKP_6dQvIO8F-Y8j8VNkopyq2eJWNgG93JEtb4klNU2dd7Kt8Kt0DlGz8Y5H_Pza8fnndm1NuUv2jsV06-_0rxlWUcw_PW7K-zqQcbhLHkB7SOkvsZjf9UPTnn63owdvsDFubJLJyF_kulcW7Tu24fv5pKRLeeFZpM_X7w9v423Rj9hIWbEQDmVbqsMuRLXsXrMsZFGM45S8I45jxkaZJkVZSmVXY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