[PATCH] D19117: [clang-tidy] Update RedundantVoidArgCheck to check for type aliases in addition to typedefs
Clement Courbet via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 14 08:48:24 PDT 2016
courbet updated this revision to Diff 53735.
courbet added a comment.
Fix error message in case of type alias declaration.
http://reviews.llvm.org/D19117
Files:
clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tidy/modernize/RedundantVoidArgCheck.h
test/clang-tidy/modernize-redundant-void-arg.cpp
Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===================================================================
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -39,6 +39,12 @@
// 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
Index: clang-tidy/modernize/RedundantVoidArgCheck.h
===================================================================
--- clang-tidy/modernize/RedundantVoidArgCheck.h
+++ clang-tidy/modernize/RedundantVoidArgCheck.h
@@ -42,8 +42,9 @@
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);
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===================================================================
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -50,7 +50,7 @@
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 @@
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 @@
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 @@
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");
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19117.53735.patch
Type: text/x-patch
Size: 4306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160414/0d4470ff/attachment.bin>
More information about the cfe-commits
mailing list