[PATCH] D14238: Fix another crash in the redundant-void-arg check.
Angel Garcia via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 08:14:51 PST 2015
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(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14238.38925.patch
Type: text/x-patch
Size: 1436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151102/fde87bae/attachment.bin>
More information about the cfe-commits
mailing list