Clang-cast is a clang tool that visits the clang AST to emit diagnostics about C style casts.
It classifies a C style cast as one that includes any combination of const/reinterpret/static casts,
one that can't be converted to a C++ cast, or a no-op cast. The tool can...
- Either warn or error on particular types of C-style casts listed above.
- Fix particular types of C-style casts listed above (in-place or in new files)
- Can emit code that's -pedantic compliant (for e.x. VLA's are used in casting)
- Give a summary of statistics of C style casts in the translation unit.
- Warn on subtleties such as member-pointer casts of different classes and more.
The tool will stop at system headers and will not visit any headers if --no-includes is set.
I also apologize for the long PR. I was developing it in my own repository here to dogfood the tool with a small set of users. Here are the most important files:
- Cast.h contains a class responsible for capturing a CStyleCastExpr node and deciding what C++ casts belong to it.
- CastOptions.h contains a set of enums and options that the users interact with in the CLI.
- ClangCast.cpp is the driver, defining the AST action.
- Matcher.h is the match callback, responsible for most of the diagnostics and handling of user input.
clang-tidy: warning: function 'requireConstCast' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
not useful