[clang-tools-extra] [clang-tidy] Flag consecutive scoped_locks in use-scoped-lock (PR #209272)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 13 19:20:41 PDT 2026


================
@@ -27,27 +27,47 @@ static bool isLockGuardDecl(const NamedDecl *Decl) {
          Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
 }
 
-static bool isLockGuard(const QualType &Type) {
+static bool isScopedLockDecl(const NamedDecl *Decl) {
+  return Decl->getDeclName().isIdentifier() &&
+         Decl->getName() == "scoped_lock" && Decl->isInStdNamespace();
+}
+
+static const NamedDecl *getLockClassDecl(const QualType &Type) {
   if (const auto *Record = Type->getAsCanonical<RecordType>())
-    if (const RecordDecl *Decl = Record->getDecl())
-      return isLockGuardDecl(Decl);
+    return Record->getDecl();
 
   if (const auto *TemplateSpecType = Type->getAs<TemplateSpecializationType>())
-    if (const TemplateDecl *Decl =
-            TemplateSpecType->getTemplateName().getAsTemplateDecl())
-      return isLockGuardDecl(Decl);
+    return TemplateSpecType->getTemplateName().getAsTemplateDecl();
 
+  return nullptr;
+}
+
+static bool isLockGuard(const QualType &Type) {
+  if (const NamedDecl *LockDecl = getLockClassDecl(Type))
+    return isLockGuardDecl(LockDecl);
   return false;
 }
 
+static bool isScopedLock(const QualType &Type) {
+  if (const NamedDecl *LockDecl = getLockClassDecl(Type))
+    return isScopedLockDecl(LockDecl);
+  return false;
+}
+
+static StringRef getLockClassName(const QualType &Type) {
+  if (const NamedDecl *LockDecl = getLockClassDecl(Type))
+    return LockDecl->getName();
+  return "";
----------------
zwuis wrote:

This branch is unused currently. Use `assert` to check if `LockDecl` is null?

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


More information about the cfe-commits mailing list