clang-tools 23.0.0git
UnusedUsingDeclsCheck.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_UNUSEDUSINGDECLSCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "llvm/ADT/SmallPtrSet.h"
14#include <vector>
15
16namespace clang::tidy::misc {
17
18/// Finds unused using declarations.
19///
20/// For the user-facing documentation see:
21/// https://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html
23public:
24 UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context);
25 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
26 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27 void onEndOfTranslationUnit() override;
28 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
29 return LangOpts.CPlusPlus;
30 }
31
32private:
33 void removeFromFoundDecls(const Decl *D);
34
35 struct UsingDeclContext {
36 explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
37 : FoundUsingDecl(FoundUsingDecl) {}
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 = false;
48 };
49
50 std::vector<UsingDeclContext> Contexts;
51 llvm::SmallPtrSet<const Decl *, 32> UsingTargetDeclsCache;
52};
53
54} // namespace clang::tidy::misc
55
56#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)