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

    <tr>
        <th>Summary</th>
        <td>
            static_cast involving pointers to members is too strict during constant evaluation
        </td>
    </tr>

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

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

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

<pre>
    The following program demonstrates this issue:
```cpp
consteval int foo(){
    struct A{char x;};
    struct B{char y;};
    struct C:A,B{};
    char C::*p=&A::x;
    char B::*q=static_cast<char B::*>(p);
    C c{};
    return((B&)c).*q;
}
int main(){
    return foo();
}
```
Clang rejects this code complaining about the static_cast, while GCC accepts it. Also, MSVC will crash with this code. This code should be fine because https://eel.is/c++draft/expr.static.cast#11.sentence-5 says "If class B contains the original member, or is a base class of the class containing the original member, the resulting pointer to member points to the original member." `B` here does not contain the member `A::x`, but it is a base class of `C` which contains the member.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE2TozYQ_TXNpWsoWTLYPnAAJk5yyClbuaaEaIxSQiKSsGf-_ZYw6_FM7RYqKFqvv55aT4agL5aogqKB4jWTSxydr_6QJj3LuxykNiLrXP9efRsJB2eMu2l7wdm7i5cT9jQ5G6KXkQLGUQfUISwEogZWQ8nuS80zsFolJF2lQW0jDs4BPwI_waEBViMihugXFbGGQ6NG6fENRAOH1_T-BGh-AN5_AWhB1DXwNgE_7a9eaTctXs8gXoGX9d3w9gXXPHD_g3gNUUat_lUyRBDtFwCI34Af59TNI0aL6mt6T3Hxdm372AAvgZ8U8FN-T5FQCc7qxM8ktf1K0N3_ibonnwfZwOrWSHtBT_-RituxKNcTKjfNRmqbTlB2bokYR8LnzniLt1Ebwt_bFqVSNMeAOuZYm-DS7l9__9PiTRuDyssw4k3H8SNDjt8eycLoFtNjRzhoS9iRkksgHGOcw8raGfiZyOQ6AD8r4A3wpvdyiMn-Nvv8Xlh-L0zsdnkgG8kqeikwyPeAwPmfAyojQ8AGlbNRahvWppzXF22lwYmmjnwq3XnUASV2MtDm5IYVfP_Z_BM5v4iQzJ7CYuJ6B5y2kTxGt0HulpAMPwmQA-cIJWugZDiSJ-wdBbQu_si8em2hoGSPsSxZSt4tEXX8WQtQsjYFvY1ajZ9p2FJnfSX6kzjJjKrdoSj2pSiPLBurYl-qQfCuKw_sxIq-kEVx2h36oTzRXhzLTFec8YIddwfO9kfG8m7oBiEOrCx6JgbRwZ7RJLXJjblOufOXbFWAalfsmRCZkR2ZsAoM55Zumz5wnvTGV8nppVsuAfbM6BDDR5ioo6HqaThR26sz1yfqwwf3SXgwOpckQKuI_eITcNUcaSMm3Vlk1M5mizfV5ym86DguXa7cBPycCtg-L7N36Q4BP69lp0Hd-rpW_HsAAAD__6YaplE">