1 //===--- UnusedUsingDeclsCheck.h - clang-tidy--------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
12 #include "../ClangTidyCheck.h"
13 #include "../utils/FileExtensionsUtils.h"
14 #include "llvm/ADT/SmallPtrSet.h"
17 namespace clang::tidy::misc
{
19 /// Finds unused using declarations.
21 /// For the user-facing documentation see:
22 /// http://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html
23 class UnusedUsingDeclsCheck
: public ClangTidyCheck
{
25 UnusedUsingDeclsCheck(StringRef Name
, ClangTidyContext
*Context
);
26 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
27 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
28 void onEndOfTranslationUnit() override
;
31 void removeFromFoundDecls(const Decl
*D
);
33 struct UsingDeclContext
{
34 explicit UsingDeclContext(const UsingDecl
*FoundUsingDecl
)
35 : FoundUsingDecl(FoundUsingDecl
), IsUsed(false) {}
36 // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
37 // can introduce multiple UsingShadowDecls in some cases (such as
38 // overloaded functions).
39 llvm::SmallPtrSet
<const Decl
*, 4> UsingTargetDecls
;
40 // The original UsingDecl.
41 const UsingDecl
*FoundUsingDecl
;
42 // The source range of the UsingDecl.
43 CharSourceRange UsingDeclRange
;
44 // Whether the UsingDecl is used.
48 std::vector
<UsingDeclContext
> Contexts
;
50 StringRef RawStringHeaderFileExtensions
;
51 FileExtensionsSet HeaderFileExtensions
;
54 } // namespace clang::tidy::misc
56 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H