clang-tools
20.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
ForwardDeclarationNamespaceCheck.h
Go to the documentation of this file.
1
//===--- ForwardDeclarationNamespaceCheck.h - clang-tidy --------*- C++ -*-===//
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_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
11
12
#include "../ClangTidyCheck.h"
13
#include "llvm/ADT/SmallPtrSet.h"
14
#include <set>
15
#include <vector>
16
17
namespace
clang::tidy::bugprone
{
18
19
/// Checks if an unused forward declaration is in a wrong namespace.
20
///
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.
24
///
25
/// \code
26
/// namespace na { struct A; }
27
/// namespace nb { struct A {} };
28
/// nb::A a;
29
/// // warning : no definition found for 'A', but a definition with the same
30
/// name 'A' found in another namespace 'nb::'
31
/// \endcode
32
///
33
/// This check can only generate warnings, but it can't suggest fixes at this
34
/// point.
35
///
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
{
39
public
:
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
;
45
46
private
:
47
llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDefinitions;
48
llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDeclarations;
49
llvm::SmallPtrSet<const Type *, 16> FriendTypes;
50
};
51
52
}
// namespace clang::tidy::bugprone
53
54
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H
Name
llvm::SmallString< 256U > Name
Definition:
ChainedComparisonCheck.cpp:42
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck
Checks if an unused forward declaration is in a wrong namespace.
Definition:
ForwardDeclarationNamespaceCheck.h:38
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ForwardDeclarationNamespaceCheck.cpp:46
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition:
ForwardDeclarationNamespaceCheck.cpp:114
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ForwardDeclarationNamespaceCheck.cpp:21
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck::ForwardDeclarationNamespaceCheck
ForwardDeclarationNamespaceCheck(StringRef Name, ClangTidyContext *Context)
Definition:
ForwardDeclarationNamespaceCheck.h:40
clang::tidy::bugprone
Definition:
ArgumentCommentCheck.cpp:19
Generated on Wed Nov 20 2024 18:24:38 for clang-tools by
1.9.6