clang-tools 10.0.0

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 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32
33 private:
34 /// Check if the given method is possible to be overridden by some other
35 /// method. Operators and destructors are excluded.
36 ///
37 /// Results are memoized in PossibleMap.
38 bool isPossibleToBeOverridden(const CXXMethodDecl *BaseMD);
39
40 /// Check if the given base method is overridden by some methods in the given
41 /// derived class.
42 ///
43 /// Results are memoized in OverriddenMap.
44 bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD,
45 const CXXRecordDecl *DerivedRD);
46
47 /// Key: the unique ID of a method.
48 /// Value: whether the method is possible to be overridden.
49 llvm::DenseMap<const CXXMethodDecl *, bool> PossibleMap;
50
51 /// Key: <unique ID of base method, name of derived class>
52 /// Value: whether the base method is overridden by some method in the derived
53 /// class.
54 llvm::DenseMap<std::pair<const CXXMethodDecl *, const CXXRecordDecl *>, bool>
55 OverriddenMap;
56
57 const unsigned EditDistanceThreshold = 1;
58 };
59
60 } // namespace bugprone
61 } // namespace tidy
62 } // namespace clang
63
64 #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:230
clang::tidy::bugprone::VirtualNearMissCheck::VirtualNearMissCheck
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
Definition: VirtualNearMissCheck.h:28
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
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
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77