angelgarcia created this revision. angelgarcia added a reviewer: alexfh. angelgarcia added subscribers: cfe-commits, klimek.
The check was assuming that a definition of a function always has a body, but a declaration that explicitly defaults or deletes a function is a definition too. http://reviews.llvm.org/D14238 Files: clang-tidy/modernize/RedundantVoidArgCheck.cpp 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 @@ -433,3 +433,9 @@ F(Foo, Bar) { } + +struct DefinitionWithNoBody { + DefinitionWithNoBody(void) = delete; + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition + // CHECK-FIXES: DefinitionWithNoBody() = delete; +}; Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp =================================================================== --- clang-tidy/modernize/RedundantVoidArgCheck.cpp +++ clang-tidy/modernize/RedundantVoidArgCheck.cpp @@ -116,9 +116,12 @@ const MatchFinder::MatchResult &Result, const FunctionDecl *Function) { SourceLocation Start = Function->getLocStart(); if (Function->isThisDeclarationADefinition()) { - SourceLocation BeforeBody = - Function->getBody()->getLocStart().getLocWithOffset(-1); - removeVoidArgumentTokens(Result, SourceRange(Start, BeforeBody), + SourceLocation End; + if (Function->hasBody()) + End = Function->getBody()->getLocStart().getLocWithOffset(-1); + else + End = Function->getLocEnd(); + removeVoidArgumentTokens(Result, SourceRange(Start, End), "function definition"); } else { removeVoidArgumentTokens(Result, Function->getSourceRange(),
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 @@ -433,3 +433,9 @@ F(Foo, Bar) { } + +struct DefinitionWithNoBody { + DefinitionWithNoBody(void) = delete; + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition + // CHECK-FIXES: DefinitionWithNoBody() = delete; +}; Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp =================================================================== --- clang-tidy/modernize/RedundantVoidArgCheck.cpp +++ clang-tidy/modernize/RedundantVoidArgCheck.cpp @@ -116,9 +116,12 @@ const MatchFinder::MatchResult &Result, const FunctionDecl *Function) { SourceLocation Start = Function->getLocStart(); if (Function->isThisDeclarationADefinition()) { - SourceLocation BeforeBody = - Function->getBody()->getLocStart().getLocWithOffset(-1); - removeVoidArgumentTokens(Result, SourceRange(Start, BeforeBody), + SourceLocation End; + if (Function->hasBody()) + End = Function->getBody()->getLocStart().getLocWithOffset(-1); + else + End = Function->getLocEnd(); + removeVoidArgumentTokens(Result, SourceRange(Start, End), "function definition"); } else { removeVoidArgumentTokens(Result, Function->getSourceRange(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits