<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114024>114024</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Failure when upcasting to a base class in trailing return type expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
rejects-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carlosgalvezp
</td>
</tr>
</table>
<pre>
Hi,
Consider this example code:
```cpp
struct Base
{};
int foo(Base&);
struct Derived : Base
{
auto f() & -> decltype(foo(static_cast<Base&>(*this)))
{
return foo(static_cast<Base&>(*this));
}
};
```
Clang emits this failure:
```console
<source>:9:32: error: non-const lvalue reference to type 'Base' cannot bind to a value of unrelated type 'Derived'
9 | auto f() & -> decltype(foo(static_cast<Base&>(*this)))
|
```
[Repro](https://godbolt.org/z/nns6EKhzM).
However, GCC accepts the code. I am confused as to why Clang complains; a Derived class should be possible to upcast to its base?
Thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE2P4zYM_TX0hUhgU7ETH3zIx7pbFL0UvReyTMdqFcmQ5MzO_PpCdmY2O0AL9NDAiAWZfOR7j5IMQV8tcwPlCcpLJuc4Ot8o6Y0LV2nu_DZlnetfm68a6Az5BfLj-n92NuiePcZRB-Rv8jYZRuV6BnF8DoQqXx81Tc_7IfpZRTzJwI_t_Qn2FxCn5yhtIw7OAR2WQKqA6k8hD6ALe33nHkEcP4EuC0REOUeHA9ABqEagCjcgvmDPysTXiYEOa6UQZdTqDyVDBHF-ryu-LInHxDc1sT4f2D8USj_PcfYW_yOkOD1DXt5JPMnyLucPZhhpr8g3HcPqxyC1mf0_W-FscOZdInEObvaKUz_iWIM4CkoqsvfOp4V1dpNSIpq7NDOj54E9W8UYHSbtEGi_stqjkta6iJ22ffoscc1xA87Ws5GR-4-ch2lA---0a4T9Gf9vv3Cp8i-aQnn6jSfvoLwAHcYYp5DkpBaovbq-cyZunb8CtW9ArbWh-vLL-PYrUL19hvnqXvjOHuiMP53PKJXiaXFpPSxb_BnlDZWzwxy4RxmSZi_jK66eKnebjNQ2gDih_BhyZWQIGEY3mx47xsmFoDuz-DFPSYm0SuPQJTlE-9zS76O0fwWgIusb0deilhk3xV7kRV3tqMrGppCl3FV5zXlR7dRQDjx0OVHFdV7ti1JluqGcdkVOdZHn-7zair4e-qovai4FVXSAXc43qc3WmPst6ZTpEGZuimKX0y4zsmMTlmuHSCWmII6Ddzay7YEoXTZEnv9kFcPmLo1edstL5puEuOnma4BdbnSI4XuNqKNZLrMVsrxgux4EfBnZPpTR9rrOZZLmoaS2GL3UJn17HNxlRPnb5DkE7Ww2e9N8mgIdx7nbKncDalMPj9dm8i41DtQupANQ--B9b-jvAAAA__9kK5vF">