<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54406>54406</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang does not properly convert the object in a member access expression
</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>
Per [class.access.base]/6, this example is ill-formed:
```
struct A {
int m;
} a;
struct B : A {};
int n = a.B::m;
```
... because the object expression `a` cannot be implicitly converted to `B` (because `B` is not a base class of `A`). Clang does not diagnose this and accepts the member access. This opens a hole in the protected member access rules:
```
struct C {
protected:
int m;
};
struct D : private C {
int get(C &c) { return c.D::m; }
};
```
This example is invalid for the same reason, but Clang accepts it. ([[class.protected]p1](https://eel.is/c++draft/class.protected#1), which normally would prevent `D` from accessing protected members on a `C` object that is not a `D` object, does not apply here because `m` as a member of the naming class `D` is private, not protected.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNU01zozAM_TVw0ZQhJiHpgUOTTM976B8QWAHvGJuxTdrur1-ZkJBke9gZvoylJ-m959rK7-oXOUg2-0aj9xk2DfGrRk_J5piI9zIRBwid8kBf2A-agD-V1i8n63qSSfGW5Mckvz7LfL6mpQ9ubAK8QbLdX_4AKBOgT4p5nWyPgLfVHL8Hhp2ztsfbbsw0vMUZ2T4WLt7ugB4rX55ZlkFNDY6eeAYCW_8mxqevwfGUyjJamSPf0KAxNnAwKB5SNSrob2isOZMLJCHYGLmPkYnYXSGvv5iRmIwQaYOJSLCnuD21JV4zOGg0LUhLl1CpsDV26oqT0UiIxA_BT2321NcsyqwFfMQYO5DhSOhslMBMcYOzgefh_h4ywI2a_H8pc1iUuYHdEn_Q6lmp46TU4NQZA92jXXJbCkwX_xZlwzTEbXAURmegyY6LhBCh_6nxo6Qfz1Y0Z9RKAttx4sRjT1wDvTXRufUYZu6vBKuQRQ3Z8TfTL6NvjsNq8v2uC2GYOBTvfBHpTHn-4DH2fEmHpxCXT_miWPGcsfBnp5qOtXY9arbSpx21ZKLoTMwLz3SMxjk528-iKW7xWU9W3bDkHHmI0bN7Q4dhsdwV6rIZK99MhsPAlTtyBHeO7WM0RivNpmGnRuIM9rGHi3uvqFxmFjciR9BbjxkPmsqqkK_FK6aBDwxVzaPLOXYgtxyk-zOozNLBbNvlWKaj09WjAq0K3Vhnje15ofX5-nrhIpfJ35X3I0WRNut1XqZdtSlOKLfl7pSj2CBtt7til-Na1lJSgWtMNdakfRW9IIShT5gg-Js9kKpK5ELkxaoUosjFKsOyxma9e13L9VbIzTZZ59Sj0lnsI7OuTV01tVSPredNrXzwyybzqlpDNJVjfBxDZ13157u12iqZTrWrqfe_n9q6KQ">