This patch implements a subset of possible replacements of C-style
casts with const_cast/static_cast/reinterpret_cast. This should cover a large
portion of cases in real code. Handling of a few more cases may be implemented
eventually.
Details
Diff Detail
Event Timeline
clang-tidy/google/AvoidCStyleCastsCheck.cpp | ||
---|---|---|
38 | nit: Grammatically, I'd prefer "needsConstCast" | |
71 | Create a test where the cast is inside a macro. I think you'll want to use the spelling location (or completely abort as the required cast type might actually be different between different macro invocations). | |
121 | Though benign now, don't fall through here. | |
test/clang-tidy/avoid-c-style-casts.cpp | ||
9 | What happens for the following code? template <typename T> void f(T t) { int i = (int)t; } f(1); f(1.0); (With the first call to f() hopefully leading to a message about a redundant cast and the second call leading to a reinterpret_cast) |
Don't analyze casts in template instantiations. Warn on casts in macros, but don't suggest fixes.
clang-tidy/google/AvoidCStyleCastsCheck.cpp | ||
---|---|---|
38 | It used to be named like this before a few rounds of refactoring. Renamed. | |
71 | To the moment we completely ignored casts in macros. Maybe we should warn, just refrain from suggesting fixes. I've implemented it this way now, please take a look. | |
121 | We definitely need to turn on -Wimplicit-fallthrough in LLVM/Clang. | |
test/clang-tidy/avoid-c-style-casts.cpp | ||
9 | Good point. Now that I avoid matches in template instantiations, fixes are not suggested for casts to/from dependent types. |
Looks good. Nice!
clang-tidy/google/AvoidCStyleCastsCheck.cpp | ||
---|---|---|
86 | I'd probably prefer "if (!ParenRange ...) return". |
nit: Grammatically, I'd prefer "needsConstCast"