blob: 170a274d70fc4f4029c8a854b5954af09e94ea37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//===--- UnusedParametersCheck.cpp - clang-tidy----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "UnusedParametersCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
parmVarDecl(hasAncestor(functionDecl().bind("function"))).bind("x"),
this);
}
void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("function");
if (!Function->doesThisDeclarationHaveABody())
return;
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("x");
if (Param->isUsed())
return;
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
<< Param->getName();
SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
MyDiag << FixItHint::CreateReplacement(
RemovalRange, (Twine(" /*") + Param->getName() + "*/").str());
}
} // namespace tidy
} // namespace clang
|