Add a check to flag the usage of C-style casts, as per Google Style
Guide:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Casting#Casting
Details
Diff Detail
Event Timeline
clang-tidy/google/CMakeLists.txt | ||
---|---|---|
4 | I think the naming is not ideal. First, the "..Check" is mostly redundant information, maybe remove that, at least for new checks. Second, it would be good to verify what is being checked with c-style casts. So, maybe DontUseCStyleCasts.cpp or AvoidCStyleCasts.cpp. | |
clang-tidy/google/CStyleCastsCheck.h | ||
22 | What is this? | |
clang-tidy/google/GoogleTidyModule.cpp | ||
25 | Maybe order alphabetically by check name? | |
test/clang-tidy/c-style-casts.cpp | ||
2 | Maybe use check_clang_tidy_output.sh to decouple the check configuration. | |
4 | Out of curiosity, why would there be a c-style cast here? |
clang-tidy/google/CMakeLists.txt | ||
---|---|---|
4 | I see some value in using the "Check" suffix for checks: it makes class names nouns in a consistent way. I like it a bit more than using imperatives (e.g. UseOverride). The matter of the check can rarely be expressed using a single short imperative statement. A few examples:
That said, AvoidCStyleCasts (though, I would prefer AvoidCStyleCastsCheck) may be an appropriate name for the check in this patch. | |
clang-tidy/google/CStyleCastsCheck.h | ||
22 | This is the name of the corresponding check in cpplint.py. I've added a comment. | |
clang-tidy/google/GoogleTidyModule.cpp | ||
25 | Done. | |
test/clang-tidy/c-style-casts.cpp | ||
2 | This script brings a bit of convenience, but it adds a requirement to use shell for tests, which limits the environments where the tests can run. However, the other script - check_clang_tidy_fix.sh - brings significant value, as it reduces a lot of shell code duplication from the RUN lines in the tests. So I'd avoid using check_clang_tidy_output.sh. I'm not sure we actually need it, maybe just for consistency in cases where we have tests both for output and for fixes. | |
4 | There's no c-style cast here. It's a utility function used below. The placement of the CHECK-NOT may be confusing though. I'll put a blank line here, so that it doesn't look like it relates to this function. We need the CHECK-NOT before the first CHECK as a generic measure to make the check more strict. |
Basically looks good, none of these other things are blockers.
clang-tidy/google/CMakeLists.txt | ||
---|---|---|
4 | I think there are pros/cons for many of these naming schemes. I'd mostly like us to settle on one and then be as consistent as possible. Regarding your arguments:
| |
test/clang-tidy/c-style-casts.cpp | ||
2 | Well, I think we either need it or not. Consistency for cases where we have a fix seems like a bad distinction as we will hopefully have fixes for almost all checks (including this one). We can fix this later (don't want to block this patch on it), but to me it seems like we should write the tests consistently (and fix this soon, before we have hundreds of tests). I don't care which way, my data-point would be that parameter changes to clang-tidy (like we have done with how the checks are configured) are significantly easier when clang-tidy is wrapped. |
I think the naming is not ideal. First, the "..Check" is mostly redundant information, maybe remove that, at least for new checks. Second, it would be good to verify what is being checked with c-style casts. So, maybe DontUseCStyleCasts.cpp or AvoidCStyleCasts.cpp.