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

Richard legalize at xmission.com
Sun Jun 28 10:24:37 PDT 2015


================
Comment at: clang-tidy/readability/RedundantVoidArgCheck.cpp:229
@@ +228,3 @@
+
+void RedundantVoidArgCheck::processNamedCastExpr(
+    const MatchFinder::MatchResult &Result, const CXXNamedCastExpr *NamedCast) {
----------------
alexfh wrote:
> 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.
Fixed.  When I took out the cStyleCast matcher, this test case fails:

```
/home/richard/dev/llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-void-arg.cpp:348:19: error: expected string not found in input
  // CHECK-FIXES: void (*f4)() = (void (*)()) 0;{{$}}
                  ^
/home/richard/dev/llvm-build/tools/clang/tools/extra/test/clang-tidy/Output/readability-redundant-void-arg.cpp.tmp.cpp:341:3: note: scanning from here
  //
  ^
/home/richard/dev/llvm-build/tools/clang/tools/extra/test/clang-tidy/Output/readability-redundant-void-arg.cpp.tmp.cpp:345:3: note: possible intended match here
  void (*f4)() = (void (*)(void)) 0;
  ^
```

So I left in the matcher for `cStyleCastExpr`.

http://reviews.llvm.org/D7639

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






More information about the cfe-commits mailing list