[PATCH] D17926: [clang-tidy] Don't delete unused parameter in class override method in anonymous namespace.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 1 00:36:41 PDT 2016
hokein updated this revision to Diff 52332.
hokein added a comment.
Code format.
http://reviews.llvm.org/D17926
Files:
clang-tidy/misc/UnusedParametersCheck.cpp
test/clang-tidy/misc-unused-parameters.cpp
Index: test/clang-tidy/misc-unused-parameters.cpp
===================================================================
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -127,6 +127,16 @@
useFunction(&C::h);
}
+class Base {
+ virtual void f(int i);
+};
+
+class Derived : public Base {
+ void f(int i) override {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void f(int /*i*/) override {}
+};
+
} // end namespace
template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -16,6 +16,13 @@
namespace clang {
namespace tidy {
+namespace {
+bool isOverrideMethod(const FunctionDecl *Function) {
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(Function))
+ return MD->size_overridden_methods() > 0 || MD->hasAttr<OverrideAttr>();
+ return false;
+}
+} // namespace
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl().bind("function"), this);
@@ -63,20 +70,15 @@
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
<< Param->getName();
- auto UsedByRef = [&] {
- return !ast_matchers::match(
- decl(hasDescendant(
- declRefExpr(to(equalsNode(Function)),
- unless(hasAncestor(
- callExpr(callee(equalsNode(Function)))))))),
- *Result.Context->getTranslationUnitDecl(), *Result.Context)
- .empty();
- };
+ auto DeclRefExpr =
+ declRefExpr(to(equalsNode(Function)),
+ unless(hasAncestor(callExpr(callee(equalsNode(Function))))));
// Comment out parameter name for non-local functions.
if (Function->isExternallyVisible() ||
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
- UsedByRef()) {
+ !ast_matchers::match(DeclRefExpr, *Result.Context).empty() ||
+ isOverrideMethod(Function)) {
SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
// Note: We always add a space before the '/*' to not accidentally create a
// '*/*' for pointer types, which doesn't start a comment. clang-format will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17926.52332.patch
Type: text/x-patch
Size: 2428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160401/93288241/attachment.bin>
More information about the cfe-commits
mailing list