<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121429>121429</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang accepts invalid `static_cast` from derived type to private base type in case of rvalue reference
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangbo15
</td>
</tr>
</table>
<pre>
Clang does not report any error for the following code:
```c++
struct A { int a;};
struct X : private A{};
int main() {
X x;
int a=static_cast<A&&>(x).a;
}
```
Please note that this can be correctly rejected if the target type is not a rvalue reference.
GCC, EDG, and MSVC reject it:
```c++
<source>: In function 'int main()':
<source>:6:29: error: 'A' is an inaccessible base of 'X'
6 | int a=static_cast<A&&>(x).a;
|
```
Please see https://godbolt.org/z/aW1s6a7ec
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyck0-L8zYQxj_N-DK8QZYSOz744DibpYdCodDurcjS2FFRpCDJ2U0_fVFs9h-0hxcGy8Z6Hs38NCNjNJMjamF3gN2xkHM6-9C-SjcNvtwVg9f3trfSTag9RXQ-YaCrDwmluyOF4AOOPmA6E47eWv9q3ITKawLRAXtExZZQwA85WBdTmFXCDqE-oHEJJYgD1Mf8fP_7giA6vAZzk4mwg_pjB7Auqy7SOOB74E02AtYhIr7g27Ipf6zex5hkMuovJWMC0XfAqxziCfj-DXizkatvffyc8HLSb5ZkpFw6YTrLhOlsIirpcCBUPgRSyd4x0N-kEmk044NGkmGihOl-JTQLOYnhJu1MGGikQE7RZjniue-B9_h0fM6LdBp__f2PfrVEk_6PJYg--jkoyuWIDn9xOM5OJeMdAq-_cgJer15fVRWIjjdZ_rjS_AK87oDXOXfp0DipFMVoBks4ZB5-zFtesuPCukKoe_wJ6g_NIv5P-pEIzyldY06fn4CfJq8Hb9PGhwn46R_gJ_lnGStZkyp0K3QjGllQW9ZiV_NtxURxbptdranSUo9bUg3Tshzllg-CVdXI9loXpuWM71jJStZsBRebYdw1g9BiP5Kk_aBgy-gijd1Ye7vkswsT40xtycstbworB7LxMU2cqzw3wHkerNBmwY9hniJsmTUxxQ-LZJKldcwy5muKaNxNWqMRKvYZY8VwDP6CmoK5kV7aK_n3MXlczdJzDtV6T9-7rpiDbb_RNOk8DxvlL8BPObF1-XENPjch8NOj0Aj8tNZ6a_m_AQAA__8yzkcW">