Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- UnusedUsingDeclsCheck.h - clang-tidy--------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/FileExtensionsUtils.h"
0014 #include "llvm/ADT/SmallPtrSet.h"
0015 #include <vector>
0016 
0017 namespace clang::tidy::misc {
0018 
0019 /// Finds unused using declarations.
0020 ///
0021 /// For the user-facing documentation see:
0022 /// http://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html
0023 class UnusedUsingDeclsCheck : public ClangTidyCheck {
0024 public:
0025   UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context);
0026   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0027   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0028   void onEndOfTranslationUnit() override;
0029   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0030     return LangOpts.CPlusPlus;
0031   }
0032 
0033 private:
0034   void removeFromFoundDecls(const Decl *D);
0035 
0036   struct UsingDeclContext {
0037     explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
0038         : FoundUsingDecl(FoundUsingDecl) {}
0039     // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
0040     // can introduce multiple UsingShadowDecls in some cases (such as
0041     // overloaded functions).
0042     llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
0043     // The original UsingDecl.
0044     const UsingDecl *FoundUsingDecl;
0045     // The source range of the UsingDecl.
0046     CharSourceRange UsingDeclRange;
0047     // Whether the UsingDecl is used.
0048     bool IsUsed = false;
0049   };
0050 
0051   std::vector<UsingDeclContext> Contexts;
0052   llvm::SmallPtrSet<const Decl *, 32> UsingTargetDeclsCache;
0053 
0054   FileExtensionsSet HeaderFileExtensions;
0055 };
0056 
0057 } // namespace clang::tidy::misc
0058 
0059 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H