[PATCH] D116425: [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses
Richard via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 30 14:34:06 PST 2021
LegalizeAdulthood created this revision.
LegalizeAdulthood added a reviewer: alexfh.
LegalizeAdulthood added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
LegalizeAdulthood requested review of this revision.
Sometimes a macro invocation will look like an argument list
declaration. Improve the check to detect this situation and not
try to modify the macro invocation.
Thanks to Nathan James for the fix.
Fixes #43791
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116425
Files:
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-redundant-void-arg.cpp
@@ -556,3 +556,9 @@
S_3<int>();
g_3<int>();
}
+
+#define return_t(T) T
+return_t(void) func(void);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: redundant void argument list in function declaration
+// CHECK-FIXES: return_t(void) func();
+#undef return_t
Index: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -97,9 +97,12 @@
void RedundantVoidArgCheck::processFunctionDecl(
const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
+ const auto *Method = dyn_cast<CXXMethodDecl>(Function);
+ SourceLocation Start = Method && Method->getParent()->isLambda()
+ ? Method->getBeginLoc()
+ : Function->getLocation();
+ SourceLocation End = Function->getEndLoc();
if (Function->isThisDeclarationADefinition()) {
- SourceLocation Start = Function->getBeginLoc();
- SourceLocation End = Function->getEndLoc();
if (const Stmt *Body = Function->getBody()) {
End = Body->getBeginLoc();
if (End.isMacroID() &&
@@ -110,7 +113,7 @@
removeVoidArgumentTokens(Result, SourceRange(Start, End),
"function definition");
} else {
- removeVoidArgumentTokens(Result, Function->getSourceRange(),
+ removeVoidArgumentTokens(Result, SourceRange(Start, End),
"function declaration");
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116425.396722.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211230/aecca3ca/attachment-0001.bin>
More information about the cfe-commits
mailing list