[PATCH] D76572: Replace `T(x)` with `reinterpret_cast<T>(x)` everywhere it means reinterpret_cast. No functional change

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 23 12:33:21 PDT 2020


rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Changes LGTM on the Clang side.

In D76572#1935791 <https://reviews.llvm.org/D76572#1935791>, @lebedev.ri wrote:

> Passing-by remark:
>
> > I wrote a Clang warning [not pictured] to diagnose any use of `T(x)` which was not equivalent to `static_cast<T>(x)`.
>
> I'm not sure whether or not this will pass the bar for a clang diagnostic


I'd like to try it out on a larger codebase, but it sounds at least potentially good to me. There's a simple syntactic workaround (use `(T)x` instead of `T(x)`), and there's a high likelihood that the code doesn't mean what the programmer intended.

Does the warning catch the cases where the code is equivalent to `static_cast<T>(x)` except that it ignores access? That seems like a really good thing to warn on regardless of whether we warn on the general case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76572/new/

https://reviews.llvm.org/D76572





More information about the cfe-commits mailing list