-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
#include <mutex>
std::mutex m0, m1;
void func() {
std::unique_lock ul1(m0, std::defer_lock);
std::unique_lock ul2(m1, std::defer_lock);
std::lock(ul1, ul2);
}
$ ~/misc/clang-cipd-latest/bin/clang++ -c -Wall -Wthread-safety /tmp/test.cc
/tmp/test.cc:9:1: warning: mutex 'ul1' is still held at the end of function [-Wthread-safety-analysis]
9 | }
| ^
/tmp/test.cc:8:3: note: mutex acquired here
8 | std::lock(ul1, ul2);
| ^
/tmp/test.cc:9:1: warning: mutex 'ul2' is still held at the end of function [-Wthread-safety-analysis]
9 | }
| ^
/tmp/test.cc:8:3: note: mutex acquired here
8 | std::lock(ul1, ul2);
| ^
2 warnings generated.
This comes up with #154078. Both mutexes should be unlocked by the unique_lock
dtors at the end of the function. Also -Wthread-safety-analysis
is incorrectly saying ul1
and ul2
are mutexes.
Metadata
Metadata
Assignees
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.