[clang-tidy] Don't delete unused parameter in class override method in anonymous namespace.
Summary: Fixes PR26740. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17926 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
a08b1fc4b8
Коммит
87fb19b74e
|
@ -16,6 +16,13 @@ using namespace clang::ast_matchers;
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
namespace tidy {
|
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) {
|
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
Finder->addMatcher(functionDecl().bind("function"), this);
|
Finder->addMatcher(functionDecl().bind("function"), this);
|
||||||
|
@ -63,20 +70,15 @@ void UnusedParametersCheck::warnOnUnusedParameter(
|
||||||
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
|
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
|
||||||
<< Param->getName();
|
<< Param->getName();
|
||||||
|
|
||||||
auto UsedByRef = [&] {
|
auto DeclRefExpr =
|
||||||
return !ast_matchers::match(
|
declRefExpr(to(equalsNode(Function)),
|
||||||
decl(hasDescendant(
|
unless(hasAncestor(callExpr(callee(equalsNode(Function))))));
|
||||||
declRefExpr(to(equalsNode(Function)),
|
|
||||||
unless(hasAncestor(
|
|
||||||
callExpr(callee(equalsNode(Function)))))))),
|
|
||||||
*Result.Context->getTranslationUnitDecl(), *Result.Context)
|
|
||||||
.empty();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Comment out parameter name for non-local functions.
|
// Comment out parameter name for non-local functions.
|
||||||
if (Function->isExternallyVisible() ||
|
if (Function->isExternallyVisible() ||
|
||||||
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
|
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
|
||||||
UsedByRef()) {
|
!ast_matchers::match(DeclRefExpr, *Result.Context).empty() ||
|
||||||
|
isOverrideMethod(Function)) {
|
||||||
SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
|
SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
|
||||||
// Note: We always add a space before the '/*' to not accidentally create a
|
// 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
|
// '*/*' for pointer types, which doesn't start a comment. clang-format will
|
||||||
|
|
|
@ -127,6 +127,16 @@ void someMoreCallSites() {
|
||||||
useFunction(&C::h);
|
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
|
} // end namespace
|
||||||
|
|
||||||
template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
|
template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
|
||||||
|
|
Загрузка…
Ссылка в новой задаче