CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
103 lines
3.1 KiB
C++
103 lines
3.1 KiB
C++
// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-scoped-lock %t -- \
|
|
// RUN: -config="{CheckOptions: {modernize-use-scoped-lock.WarnOnSingleLocks: false}}" \
|
|
// RUN: -- -fno-delayed-template-parsing
|
|
|
|
#include <mutex>
|
|
|
|
void Positive() {
|
|
std::mutex m;
|
|
|
|
{
|
|
std::lock_guard<std::mutex> l1(m);
|
|
std::lock_guard<std::mutex> l2(m);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:33: note: additional 'std::lock_guard' declared here
|
|
}
|
|
|
|
{
|
|
std::lock_guard<std::mutex> l1(m), l2(m), l3(m);
|
|
std::lock_guard<std::mutex> l4(m);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:40: note: additional 'std::lock_guard' declared here
|
|
// CHECK-MESSAGES: :[[@LINE-4]]:47: note: additional 'std::lock_guard' declared here
|
|
// CHECK-MESSAGES: :[[@LINE-4]]:33: note: additional 'std::lock_guard' declared here
|
|
}
|
|
|
|
{
|
|
std::lock(m, m);
|
|
std::lock_guard<std::mutex> l1(m, std::adopt_lock);
|
|
std::lock_guard<std::mutex> l2(m, std::adopt_lock);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:33: note: additional 'std::lock_guard' declared here
|
|
}
|
|
}
|
|
|
|
void Negative() {
|
|
std::mutex m;
|
|
{
|
|
std::lock_guard<std::mutex> l(m);
|
|
}
|
|
|
|
{
|
|
std::lock_guard<std::mutex> l(m, std::adopt_lock);
|
|
}
|
|
|
|
{
|
|
std::lock_guard<std::mutex> l3(m);
|
|
int a = 0;
|
|
std::lock_guard<std::mutex> l4(m, std::adopt_lock);
|
|
}
|
|
}
|
|
|
|
void PositiveInsideArg(std::mutex &m1, std::mutex &m2, std::mutex &m3) {
|
|
std::lock_guard<std::mutex> l1(m1);
|
|
std::lock_guard<std::mutex> l2(m2);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:31: note: additional 'std::lock_guard' declared here
|
|
}
|
|
|
|
|
|
void NegativeInsideArg(std::mutex &m1, std::mutex &m2, std::mutex &m3) {
|
|
std::lock_guard<std::mutex> l3(m3);
|
|
}
|
|
|
|
template <typename T>
|
|
void PositiveTemplated() {
|
|
std::mutex m1, m2;
|
|
|
|
std::lock_guard<std::mutex> l1(m1);
|
|
std::lock_guard<std::mutex> l2(m2);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:31: note: additional 'std::lock_guard' declared here
|
|
}
|
|
|
|
template <typename T>
|
|
void NegativeTemplated() {
|
|
std::mutex m1, m2, m3;
|
|
std::lock_guard<std::mutex> l(m1);
|
|
}
|
|
|
|
template <typename Mutex>
|
|
void PositiveTemplatedMutex() {
|
|
Mutex m1, m2;
|
|
|
|
std::lock_guard<Mutex> l1(m1);
|
|
std::lock_guard<Mutex> l2(m2);
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use single 'std::scoped_lock' instead of multiple 'std::lock_guard'
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:26: note: additional 'std::lock_guard' declared here
|
|
}
|
|
|
|
template <typename Mutex>
|
|
void NegativeTemplatedMutex() {
|
|
Mutex m1;
|
|
std::lock_guard<Mutex> l(m1);
|
|
}
|
|
|
|
struct NegativeClass {
|
|
void Negative() {
|
|
std::lock_guard<std::mutex> l(m1);
|
|
}
|
|
|
|
std::mutex m1;
|
|
};
|