<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68532>68532</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Detect obfuscation of reinterpret_cast
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carlosgalvezp
</td>
</tr>
</table>
<pre>
Hi!
This is a check request / enhancement request of an existing check.
Today, we have the check `cppcoreguidelines-pro-type-reinterpret-cast` to warn about usages of `reinterpret_cast`. What people end up doing to work around the warning is changing this code:
```
float y = *reinterpret_cast<float*>(&x);
```
Into:
```
float y = *static_cast<float*>(static_cast<void*>(&x));
```
However, both expressions are equivalent, as per [the Standard](https://eel.is/c++draft/expr.reinterpret.cast#7).
We would therefore like to flag this case as well. One could argue that obfuscating the code is more dangerous than having the explicit `reinterpret_cast` in the first place, because it's easier to miss in code review and search for afterwards.
So, to check for this case, I believe it could be done in 2 ways:
- Add a `readability` check that tells the user to replace the obfuscated code with an explicit `reinterpret_cast`, or:
- Extend the `cppcoreguidelines-pro-type-reinterpret-cast` check to cover this case as well (potentially opt-in via configuration).
What do you think?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE1v4zYQ_TX0ZWBBpmJHPugQx2vsnnrYAnssRuRIYkOTWnIo2_31BWUndTbbFgsECkw-vnlvvjBG0zuiRqx3Yr1fYOLBh0ZhsD72aCf6a1y0Xl-az0bIlSj3ony6fn8fTAQTAUENpF4g0PdEkUHIA5Ab0Ck6kuO3c98BOqCziWxcf31UwDtGr_Ei5DOcCAacCHigG7nYlGoclQ_UJ6PJGkdxOQa_5MtIy0DGMYUxEC8VRhabEtjDCYMDbH1iSBF7ilmD2JR38D9u8AK-Dcgwkh8tATkNaQTts9BM5MMLYPDJ6VlTJs5XJoIa0PUzLKdDeU2iero3JTbl7W_-2VmPDBcQ1R6EfP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