Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ForwardDeclarationNamespaceCheck.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_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "llvm/ADT/SmallPtrSet.h"
0014 #include <set>
0015 #include <vector>
0016 
0017 namespace clang::tidy::bugprone {
0018 
0019 /// Checks if an unused forward declaration is in a wrong namespace.
0020 ///
0021 /// The check inspects all unused forward declarations and checks if there is
0022 /// any declaration/definition with the same name, which could indicate
0023 /// that the forward declaration is potentially in a wrong namespace.
0024 ///
0025 /// \code
0026 ///   namespace na { struct A; }
0027 ///   namespace nb { struct A {} };
0028 ///   nb::A a;
0029 ///   // warning : no definition found for 'A', but a definition with the same
0030 ///   name 'A' found in another namespace 'nb::'
0031 /// \endcode
0032 ///
0033 /// This check can only generate warnings, but it can't suggest fixes at this
0034 /// point.
0035 ///
0036 /// For the user-facing documentation see:
0037 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/forward-declaration-namespace.html
0038 class ForwardDeclarationNamespaceCheck : public ClangTidyCheck {
0039 public:
0040   ForwardDeclarationNamespaceCheck(StringRef Name, ClangTidyContext *Context)
0041       : ClangTidyCheck(Name, Context) {}
0042   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0043   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0044   void onEndOfTranslationUnit() override;
0045 
0046 private:
0047   llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDefinitions;
0048   llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDeclarations;
0049   llvm::SmallPtrSet<const Type *, 16> FriendTypes;
0050 };
0051 
0052 } // namespace clang::tidy::bugprone
0053 
0054 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H