1 //===--- ForwardDeclarationNamespaceCheck.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_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "llvm/ADT/SmallPtrSet.h"
17 namespace clang::tidy::bugprone
{
19 /// Checks if an unused forward declaration is in a wrong namespace.
21 /// The check inspects all unused forward declarations and checks if there is
22 /// any declaration/definition with the same name, which could indicate
23 /// that the forward declaration is potentially in a wrong namespace.
26 /// namespace na { struct A; }
27 /// namespace nb { struct A {} };
29 /// // warning : no definition found for 'A', but a definition with the same
30 /// name 'A' found in another namespace 'nb::'
33 /// This check can only generate warnings, but it can't suggest fixes at this
36 /// For the user-facing documentation see:
37 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/forward-declaration-namespace.html
38 class ForwardDeclarationNamespaceCheck
: public ClangTidyCheck
{
40 ForwardDeclarationNamespaceCheck(StringRef Name
, ClangTidyContext
*Context
)
41 : ClangTidyCheck(Name
, Context
) {}
42 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
43 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
44 void onEndOfTranslationUnit() override
;
47 llvm::StringMap
<std::vector
<const CXXRecordDecl
*>> DeclNameToDefinitions
;
48 llvm::StringMap
<std::vector
<const CXXRecordDecl
*>> DeclNameToDeclarations
;
49 llvm::SmallPtrSet
<const Type
*, 16> FriendTypes
;
52 } // namespace clang::tidy::bugprone
54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H