[PATCH] Add readability-redundant-void-arg check to clang-tidy

Alexander Kornienko alexfh at google.com
Tue Jun 23 03:20:43 PDT 2015


Something wrong happened with this patch: there are tons of unrelated changes here. Maybe you need to update your working copy?


================
Comment at: clang-tidy/readability/RedundantVoidArgCheck.cpp:50
@@ +49,3 @@
+void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(functionDecl(isExpansionInMainFile(), parameterCountIs(0),
+                                  unless(isImplicit()),
----------------
So why do we need `isExpansionInMainFile()` here and in all other matchers? ClangTidy has its own mechanism to filter warnings by location.

================
Comment at: clang-tidy/readability/RedundantVoidArgCheck.cpp:229
@@ +228,3 @@
+
+void RedundantVoidArgCheck::processNamedCastExpr(
+    const MatchFinder::MatchResult &Result, const CXXNamedCastExpr *NamedCast) {
----------------
Now `processNamedCastExpr`, `processNamedCastExpr` and `processFunctionalCast` methods are almost identical and can be replaced by a single method. And I think this method should be `processExplicitCastExpr` that should have the same implementation.

BTW, currently, the `processExplicitCastExpr` method can only be called if the code encounters the only class inherited from `ExplicitCastExpr` that is not handled explicitly: `ObjCBridgedCastExpr`.

Once again: replace `processExplicitCastExpr` implementation with this:
```
void RedundantVoidArgCheck::processExplicitCastExpr(
    const MatchFinder::MatchResult &Result,
    const ExplicitCastExpr *ExplicitCast) {
  if (protoTypeHasNoParms(ExplicitCast->getTypeAsWritten())) {
    removeVoidArgumentTokens(
      Result,
      ExplicitCast->getTypeInfoAsWritten()->getTypeLoc().getSourceRange(),
       "cast expression");
  }
}
```
... and remove the other three `process...Cast` methods and the corresponding `if` branches.

Also, register a single `explicitCastExpr` matcher instead of separate matchers for all kinds of casts.

http://reviews.llvm.org/D7639

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list