[PATCH] D136156: [Clang][Diagnostic] Add hidden-reinterpret-cast diagnostic warning
Tom Weaver via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 24 06:00:10 PST 2022
TWeaver added a comment.
Hello all,
First of all, thank you so much for your reviews, comments and time.
Secondly, I apologise for the late reply.
I've be thinking about your statements and I have to somewhat agree. This doesn't catch undefined behaviour, at least by its self. It may help catch undefined behaviour as a result of 'bad-code', but it's not going to catch UB as a result of the cast in every case. The clang-tidy checks are fine but they don't actually drill down to the functionality I'm looking for, aka, "this functional cast is a reinterpret_cast - beware!" (missing from this patch is a suggestion to write 'reinterpret_cast<T>(...)' instead).
Also, I'm aware that there's a warning for picking up old style c casts in the compiler, enabled by providing '-Wold-style-cast' on the command line. Are old style c casts not also language features? If that's the case why is its diagnostic embedded in the compiler and not in clang-tidy?
I ask this because there's an argument to be made that C++ style functional casts are just as dangerous as old-style casts. They can produce reinterpret casts when used in the right (or wrong) context. Would it be possible to at least add a diagnostic for detecting any functional style casts instead?
$ clang.exe .\old-style-test.cpp -Wold-style-cast
.\old-style-test.cpp:3:11: warning: use of old-style cast [-Wold-style-cast]
int y = (double)x;
^
Thanks again for your time
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136156/new/
https://reviews.llvm.org/D136156
More information about the cfe-commits
mailing list