Issue 117919
Summary `-Wthread-safety-negative` reported with seemingly correctly annotated code
Labels
Assignees
Reporter firewave
    ```cpp
#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://reviews.llvm.org/D84604

There is some discussion about this in the patch which introduced this: https://reviews.llvm.org/D84604.

CC @aaronpuchert @AaronBallman @LebedevRI 
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to