<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/134867>134867</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
reinterpret_cast from const void* to function pointer does not compile
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
StilesCrisis
</td>
</tr>
</table>
<pre>
GCC and MSVC both allow a reinterpret_cast to convert from a `const void*` to `void (*)(void*)`.
Clang refuses because we are "casting away qualifiers" (const), but there is no qualifier to add on the function-pointer side. There is no syntax for assigning values into a function pointer and there is no possible addition of `const` into the function pointer type which makes the cast allowed.
This can be worked around by using const_cast to strip the const off the void*, or by using a C-style cast, but this seems like it shouldn't be necessary, and no other mainstream compiler requires it.
Example: https://godbolt.org/z/7rxqss7nT
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkk8GSgzYMhp_GXDTJgIAABw4pbXrqaXd67RgQwV1js5ZJNn36jp3dZNs9MdjS_0ufLMmszoaoFeUvovw1kZufrWtfvNLEnVOsOOnteGt_7zqQZoQ_Xv7soLd-Bqm1vYIER8p4cqsj_9cg2YO3MFhzIedhcnYBCeKQDtawh4tVo8CjOKQhShzScAAC63CIjcD6KwIbcUj3INKjSI-dluYMjqaNiaGnQW5McCWQjkAgBltlziCv8gbvm9RqUuRYIAbtaB3VO-g3D34mR6AYjH0Gh3rkOII14R6mzQxeWbNbbewOWI20h9dvqXwzXn7AZB3cKYYKLlJvxKBMkHuowJdKIPjdfrXMqtcUrFWMtNODVqAUhb4X9JDyt5XgOqthhkW-EceoyD8Ohsb9nd3rrBgGaaAnuFr3RiNIZzczQn-DjUPR0e0xO_ZOrXe1ODM7TfHvMZkOrHsmS-h27G_6bv5krBiYaGHQ6o1AeeDZbno0AisfajE0ELN0t5ASuBgLNrCBRSrD3pFcYLDLqjQ5cPS-KRfI-s--fvuQy6pJ5EeYvV9Z5EeBJ4Gnsx17q_3eurPA0z8CT5X7eGeuzGsytvnY5I1MqM2qosiwrMsmmdsGD4OUJQ5ZmfY1VlPWZD32lJVZ08giT1SLKZZpkdZZiUXW7PuKpjyvqxppSKtxEEVKi1R6r_VlCd6JYt6ozfKiPlSJlj1pjluGaOgK8VYghqVzbUja9duZRZFqxZ6fMl55Te2PJYub9Z-lCrP78UpGS-Gh-S-SyeZ0-z9eys9bvx_sIvAUbD8_u9XZv2nwAk-xWBZ4-uzm0uK_AQAA__9-9G5x">