[clang-tools-extra] r266358 - Add support for type aliases to modernize-redundant-void-arg.cpp

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 12:28:13 PDT 2016


Author: aaronballman
Date: Thu Apr 14 14:28:13 2016
New Revision: 266358

URL: http://llvm.org/viewvc/llvm-project?rev=266358&view=rev
Log:
Add support for type aliases to modernize-redundant-void-arg.cpp

Patch by Clement Courbet.

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
    clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.h
    clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp?rev=266358&r1=266357&r2=266358&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.cpp Thu Apr 14 14:28:13 2016
@@ -50,7 +50,7 @@ void RedundantVoidArgCheck::registerMatc
                                   unless(isExternC()))
                          .bind(FunctionId),
                      this);
-  Finder->addMatcher(typedefDecl().bind(TypedefId), this);
+  Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
   auto ParenFunctionType = parenType(innerType(functionType()));
   auto PointerToFunctionType = pointee(ParenFunctionType);
   auto FunctionOrMemberPointer =
@@ -80,8 +80,9 @@ void RedundantVoidArgCheck::check(const
   const BoundNodes &Nodes = Result.Nodes;
   if (const auto *Function = Nodes.getNodeAs<FunctionDecl>(FunctionId)) {
     processFunctionDecl(Result, Function);
-  } else if (const auto *Typedef = Nodes.getNodeAs<TypedefDecl>(TypedefId)) {
-    processTypedefDecl(Result, Typedef);
+  } else if (const auto *TypedefName =
+                 Nodes.getNodeAs<TypedefNameDecl>(TypedefId)) {
+    processTypedefNameDecl(Result, TypedefName);
   } else if (const auto *Member = Nodes.getNodeAs<FieldDecl>(FieldId)) {
     processFieldDecl(Result, Member);
   } else if (const auto *Var = Nodes.getNodeAs<VarDecl>(VarId)) {
@@ -105,8 +106,8 @@ void RedundantVoidArgCheck::processFunct
   if (Function->isThisDeclarationADefinition()) {
     const Stmt *Body = Function->getBody();
     SourceLocation Start = Function->getLocStart();
-    SourceLocation End = Body ? Body->getLocStart().getLocWithOffset(-1) :
-                                Function->getLocEnd();
+    SourceLocation End =
+        Body ? Body->getLocStart().getLocWithOffset(-1) : Function->getLocEnd();
     removeVoidArgumentTokens(Result, SourceRange(Start, End),
                              "function definition");
   } else {
@@ -179,10 +180,13 @@ void RedundantVoidArgCheck::removeVoidTo
   diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidRange);
 }
 
-void RedundantVoidArgCheck::processTypedefDecl(
-    const MatchFinder::MatchResult &Result, const TypedefDecl *Typedef) {
-  if (protoTypeHasNoParms(Typedef->getUnderlyingType())) {
-    removeVoidArgumentTokens(Result, Typedef->getSourceRange(), "typedef");
+void RedundantVoidArgCheck::processTypedefNameDecl(
+    const MatchFinder::MatchResult &Result,
+    const TypedefNameDecl *TypedefName) {
+  if (protoTypeHasNoParms(TypedefName->getUnderlyingType())) {
+    removeVoidArgumentTokens(Result, TypedefName->getSourceRange(),
+                             isa<TypedefDecl>(TypedefName) ? "typedef"
+                                                           : "type alias");
   }
 }
 

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.h?rev=266358&r1=266357&r2=266358&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RedundantVoidArgCheck.h Thu Apr 14 14:28:13 2016
@@ -42,8 +42,9 @@ private:
   void processFunctionDecl(const ast_matchers::MatchFinder::MatchResult &Result,
                            const FunctionDecl *Function);
 
-  void processTypedefDecl(const ast_matchers::MatchFinder::MatchResult &Result,
-                          const TypedefDecl *Typedef);
+  void
+  processTypedefNameDecl(const ast_matchers::MatchFinder::MatchResult &Result,
+                         const TypedefNameDecl *Typedef);
 
   void processFieldDecl(const ast_matchers::MatchFinder::MatchResult &Result,
                         const FieldDecl *Member);

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp?rev=266358&r1=266357&r2=266358&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-redundant-void-arg.cpp Thu Apr 14 14:28:13 2016
@@ -39,6 +39,12 @@ typedef int (*returns_fn_void_int_t(void
 // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: {{.*}} in typedef
 // CHECK-FIXES: {{^}}typedef int (*returns_fn_void_int_t())();{{$}}
 
+// Should work for type aliases as well as typedef.
+using returns_fn_void_int_t2 = int (*(void))(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: {{.*}} in type alias
+// CHECK-MESSAGES: :[[@LINE-2]]:46: warning: {{.*}} in type alias
+// CHECK-FIXES: {{^}}using returns_fn_void_int_t2 = int (*())();{{$}}
+
 int (*returns_fn_void_int(void))(void) {
 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function definition
 // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function definition




More information about the cfe-commits mailing list