clang-tools
6.0.0
llvm.src
tools
clang
tools
extra
clang-tidy
bugprone
VirtualNearMissCheck.h
Go to the documentation of this file.
1
//===--- VirtualNearMissCheck.h - clang-tidy---------------------*- C++ -*-===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
11
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
12
13
#include "../ClangTidy.h"
14
#include "llvm/ADT/DenseMap.h"
15
16
namespace
clang
{
17
namespace
tidy {
18
namespace
bugprone {
19
20
/// \brief Checks for near miss of virtual methods.
21
///
22
/// For a method in a derived class, this check looks for virtual method with a
23
/// very similar name and an identical signature defined in a base class.
24
///
25
/// For the user-facing documentation see:
26
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-virtual-near-miss.html
27
class
VirtualNearMissCheck
:
public
ClangTidyCheck
{
28
public
:
29
VirtualNearMissCheck
(StringRef
Name
,
ClangTidyContext
*Context)
30
:
ClangTidyCheck
(Name, Context) {}
31
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
32
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
33
34
private
:
35
/// Check if the given method is possible to be overridden by some other
36
/// method. Operators and destructors are excluded.
37
///
38
/// Results are memoized in PossibleMap.
39
bool
isPossibleToBeOverridden(
const
CXXMethodDecl *BaseMD);
40
41
/// Check if the given base method is overridden by some methods in the given
42
/// derived class.
43
///
44
/// Results are memoized in OverriddenMap.
45
bool
isOverriddenByDerivedClass(
const
CXXMethodDecl *BaseMD,
46
const
CXXRecordDecl *DerivedRD);
47
48
/// Key: the unique ID of a method.
49
/// Value: whether the method is possible to be overridden.
50
llvm::DenseMap<const CXXMethodDecl *, bool> PossibleMap;
51
52
/// Key: <unique ID of base method, name of derived class>
53
/// Value: whether the base method is overridden by some method in the derived
54
/// class.
55
llvm::DenseMap<std::pair<const CXXMethodDecl *, const CXXRecordDecl *>,
bool
>
56
OverriddenMap;
57
58
const
unsigned
EditDistanceThreshold = 1;
59
};
60
61
}
// namespace bugprone
62
}
// namespace tidy
63
}
// namespace clang
64
65
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
clang::tidy::bugprone::VirtualNearMissCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
VirtualNearMissCheck.cpp:229
Name
StringHandle Name
Definition:
PreprocessorTracker.cpp:525
clang::tidy::bugprone::VirtualNearMissCheck::VirtualNearMissCheck
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
Definition:
VirtualNearMissCheck.h:29
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
clang::tidy::bugprone::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition:
VirtualNearMissCheck.h:27
clang::tidy::bugprone::VirtualNearMissCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
VirtualNearMissCheck.cpp:216
clang
Definition:
AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:104
Generated on Thu Feb 8 2018 09:13:45 for clang-tools by
1.8.13