clang-tools
11.0.0
clang-tools-extra
clang-tidy
bugprone
VirtualNearMissCheck.h
Go to the documentation of this file.
1
//===--- VirtualNearMissCheck.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_VIRTUAL_NEAR_MISS_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
11
12
#include "../ClangTidyCheck.h"
13
#include "llvm/ADT/DenseMap.h"
14
15
namespace
clang
{
16
namespace
tidy {
17
namespace
bugprone {
18
19
/// Checks for near miss of virtual methods.
20
///
21
/// For a method in a derived class, this check looks for virtual method with a
22
/// very similar name and an identical signature defined in a base class.
23
///
24
/// For the user-facing documentation see:
25
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-virtual-near-miss.html
26
class
VirtualNearMissCheck
:
public
ClangTidyCheck
{
27
public
:
28
VirtualNearMissCheck
(StringRef
Name
,
ClangTidyContext
*Context)
29
:
ClangTidyCheck
(
Name
, Context) {}
30
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
31
return
LangOpts.CPlusPlus;
32
}
33
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
34
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
35
36
private
:
37
/// Check if the given method is possible to be overridden by some other
38
/// method. Operators and destructors are excluded.
39
///
40
/// Results are memoized in PossibleMap.
41
bool
isPossibleToBeOverridden(
const
CXXMethodDecl *BaseMD);
42
43
/// Check if the given base method is overridden by some methods in the given
44
/// derived class.
45
///
46
/// Results are memoized in OverriddenMap.
47
bool
isOverriddenByDerivedClass(
const
CXXMethodDecl *BaseMD,
48
const
CXXRecordDecl *DerivedRD);
49
50
/// Key: the unique ID of a method.
51
/// Value: whether the method is possible to be overridden.
52
llvm::DenseMap<const CXXMethodDecl *, bool> PossibleMap;
53
54
/// Key: <unique ID of base method, name of derived class>
55
/// Value: whether the base method is overridden by some method in the derived
56
/// class.
57
llvm::DenseMap<std::pair<const CXXMethodDecl *, const CXXRecordDecl *>,
bool
>
58
OverriddenMap;
59
60
const
unsigned
EditDistanceThreshold = 1;
61
};
62
63
}
// namespace bugprone
64
}
// namespace tidy
65
}
// namespace clang
66
67
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:114
clang::tidy::bugprone::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition:
VirtualNearMissCheck.h:26
clang::tidy::bugprone::VirtualNearMissCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
VirtualNearMissCheck.cpp:217
clang::tidy::bugprone::VirtualNearMissCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition:
VirtualNearMissCheck.h:30
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:76
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::bugprone::VirtualNearMissCheck::VirtualNearMissCheck
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
Definition:
VirtualNearMissCheck.h:28
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:227
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
Generated on Tue Jul 28 2020 16:14:05 for clang-tools by
1.8.16