[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 19 15:32:09 PDT 2023


================
@@ -18,24 +18,26 @@ using namespace clang;
 
 namespace {
 
-bool hasPublicRefAndDeref(const CXXRecordDecl *R) {
+bool hasPublicRefMethod(const CXXRecordDecl *R) {
   assert(R);
   assert(R->hasDefinition());
 
-  bool hasRef = false;
-  bool hasDeref = false;
   for (const CXXMethodDecl *MD : R->methods()) {
     const auto MethodName = safeGetName(MD);
+    if (MethodName == "ref" && MD->getAccess() == AS_public)
+      return true;
+  }
+  return false;
+}
 
-    if (MethodName == "ref" && MD->getAccess() == AS_public) {
-      if (hasDeref)
-        return true;
-      hasRef = true;
-    } else if (MethodName == "deref" && MD->getAccess() == AS_public) {
-      if (hasRef)
-        return true;
-      hasDeref = true;
-    }
+bool hasPublicDerefMethod(const CXXRecordDecl *R) {
----------------
haoNoQ wrote:

It's probably a good idea to deduplicate some code here, eg. have a function `hasPublicMethod[InBase]WithName(string)` and pass `"Ref"` and `"Deref"` as parameters.

https://github.com/llvm/llvm-project/pull/68170


More information about the cfe-commits mailing list