-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed as not planned
Closed as not planned
Copy link
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Description
#include <mutex>
#include <set>
#include <string>
class C
{
void f(std::string s)
{
std::lock_guard<std::mutex> l(mSync);
mObject.emplace(std::move(s));
}
private:
std::mutex mSync;
std::set<std::string> mObject __attribute__((guarded_by(mSync)));
};Building with -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -stdlib=libc++ -Weverything gives the following:
<source>:9:37: warning: acquiring mutex 'mSync' requires negative capability '!mSync' [-Wthread-safety-negative]
9 | std::lock_guard<std::mutex> l(mSync);
| ^
<source>:8:5: note: thread warning in function 'f'
8 | {
| ^
https://godbolt.org/z/d7q7s9jK7
There is some discussion about this in the patch which introduced this: https://reviews.llvm.org/D84604.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!