clang-tools 10.0.0

UnusedUsingDeclsCheck.h
Go to the documentation of this file.
1 //===--- UnusedUsingDeclsCheck.h - clang-tidy--------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
11
12 #include "../ClangTidyCheck.h"
13 #include "llvm/ADT/SmallPtrSet.h"
14 #include <vector>
15
16 namespace clang {
17 namespace tidy {
18 namespace misc {
19
20 /// Finds unused using declarations.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-unused-using-decls.html
24 class UnusedUsingDeclsCheck : public ClangTidyCheck {
25 public:
26 UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)
27 : ClangTidyCheck(Name, Context) {}
28 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30 void onEndOfTranslationUnit() override;
31
32 private:
33 void removeFromFoundDecls(const Decl *D);
34
35 struct UsingDeclContext {
36 explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
37 : FoundUsingDecl(FoundUsingDecl), IsUsed(false) {}
38 // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
39 // can introduce multiple UsingShadowDecls in some cases (such as
40 // overloaded functions).
41 llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
42 // The original UsingDecl.
43 const UsingDecl *FoundUsingDecl;
44 // The source range of the UsingDecl.
45 CharSourceRange UsingDeclRange;
46 // Whether the UsingDecl is used.
47 bool IsUsed;
48 };
49
50 std::vector<UsingDeclContext> Contexts;
51 };
52
53 } // namespace misc
54 } // namespace tidy
55 } // namespace clang
56
57 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
Decl
const FunctionDecl * Decl
Definition: AvoidBindCheck.cpp:93
clang::tidy::misc::UnusedUsingDeclsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: UnusedUsingDeclsCheck.cpp:53
clang::tidy::misc::UnusedUsingDeclsCheck::UnusedUsingDeclsCheck
UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)
Definition: UnusedUsingDeclsCheck.h:26
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::misc::UnusedUsingDeclsCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition: UnusedUsingDeclsCheck.cpp:170
clang::tidy::misc::UnusedUsingDeclsCheck
Finds unused using declarations.
Definition: UnusedUsingDeclsCheck.h:24
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::misc::UnusedUsingDeclsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: UnusedUsingDeclsCheck.cpp:71
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
IsUsed
bool IsUsed
Definition: AvoidBindCheck.cpp:79