clang-tools  7.0.0
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
28 public:
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
llvm::StringRef Name
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
Checks for near miss of virtual methods.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.