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

    <tr>
        <th>Summary</th>
        <td>
            miscomputation of function type taking address of function with `decltype(auto)` return type deduced as const-qualified
        </td>
    </tr>

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

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

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

<pre>
    Testcase:

```c++
const int n = 0;

template <class = void>
decltype(auto) g() {
    return n;
}

const int (&r)() = g<>;
```

The initialization of `r` fails, with clang complaining that it can't match `decltype(auto)` against `const `int`:

```console
<source>:9:24: error: address of overloaded function 'g' does not match required type 'const int ()'
    9 |     const int (&r)() = g<>;
      | ^~~
<source>:4:16: note: candidate template ignored: could not match 'decltype(auto)' against 'const int'
    4 | decltype(auto) g() {
 |                ^
```

This works fine if the `const` is removed in both places -- not all address-of-overloaded-function deductions fail with `decltype(auto)`. Also, if `const` is just removed from `r`, we get:

```console
<source>:8:14: error: address of overloaded function 'g' does not match required type 'int ()'
    8 | int (&r)() = g<>;
      |              ^~~
<source>:4:16: note: candidate template ignored: could not match 'const int ()' against 'int ()'
    4 | decltype(auto) g() {
      |                ^
```

... so Clang *does* know the return type is `const int`. Perhaps we're incorrectly removing top-level cv-qualifiers from the deduced return type at some stage?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0lc-S2ygQxp-mfemySwZLsg46eOzxeQ95AQwtiQwGB5Bdk0OefQv8d2Znskmq4lJZlKSG_r7-0YgQdG-JWiifoNxMxBgH59vvr70zTqvJzqnX9guFKEUg4CsoNlBc_6vifElgT-nKT6WzIaK2ES0C32AB_OkxKtL-YEQkBL6WRoSQvzo6rYA_nz9RJE18PRCwpRijA9ZgD2yZ7lBfJkNE9BRHb9HeV6g3j0vdU8nRlQfWXOfhG-yBr9Oat-irns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