[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 10 12:58:34 PST 2025
================
@@ -0,0 +1,81 @@
+.. title:: clang-tidy - modernize-use-scoped-lock
+
+modernize-use-scoped-lock
+=========================
+
+Finds uses of ``std::lock_guard`` and suggests replacing them with C++17's more
+flexible and safer alternative ``std::scoped_lock``. The check will
+automatically transform only single declarations of ``std::lock_guard`` and
+emit warnings for multiple declarations of ``std::lock_guard`` that can be
+replaced with a single declaration of ``std::scoped_lock``.
+
+Examples
+--------
+
+Single ``std::lock_guard`` declaration:
+
+.. code-block:: c++
+
+ std::mutex M;
+ std::lock_guard<std::mutex> L(M);
+
+
+Transforms to:
+
+.. code-block:: c++
+
+ std::mutex m;
----------------
PiotrZSL wrote:
```suggestion
std::mutex M;
```
https://github.com/llvm/llvm-project/pull/126434
More information about the cfe-commits
mailing list