|
|
|||
File indexing completed on 2026-05-10 08:36:19
0001 //===--- VirtualNearMissCheck.h - clang-tidy---------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H 0011 0012 #include "../ClangTidyCheck.h" 0013 #include "llvm/ADT/DenseMap.h" 0014 0015 namespace clang::tidy::bugprone { 0016 0017 /// Checks for near miss of virtual methods. 0018 /// 0019 /// For a method in a derived class, this check looks for virtual method with a 0020 /// very similar name and an identical signature defined in a base class. 0021 /// 0022 /// For the user-facing documentation see: 0023 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/virtual-near-miss.html 0024 class VirtualNearMissCheck : public ClangTidyCheck { 0025 public: 0026 VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context) 0027 : ClangTidyCheck(Name, Context) {} 0028 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 0029 return LangOpts.CPlusPlus; 0030 } 0031 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0032 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0033 0034 private: 0035 /// Check if the given method is possible to be overridden by some other 0036 /// method. Operators and destructors are excluded. 0037 /// 0038 /// Results are memoized in PossibleMap. 0039 bool isPossibleToBeOverridden(const CXXMethodDecl *BaseMD); 0040 0041 /// Check if the given base method is overridden by some methods in the given 0042 /// derived class. 0043 /// 0044 /// Results are memoized in OverriddenMap. 0045 bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD, 0046 const CXXRecordDecl *DerivedRD); 0047 0048 /// Key: the unique ID of a method. 0049 /// Value: whether the method is possible to be overridden. 0050 llvm::DenseMap<const CXXMethodDecl *, bool> PossibleMap; 0051 0052 /// Key: <unique ID of base method, name of derived class> 0053 /// Value: whether the base method is overridden by some method in the derived 0054 /// class. 0055 llvm::DenseMap<std::pair<const CXXMethodDecl *, const CXXRecordDecl *>, bool> 0056 OverriddenMap; 0057 0058 const unsigned EditDistanceThreshold = 1; 0059 }; 0060 0061 } // namespace clang::tidy::bugprone 0062 0063 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|