<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/117919>117919</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `-Wthread-safety-negative` reported with seemingly correctly annotated code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          firewave
      </td>
    </tr>
</table>

<pre>
    ```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 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVF2PqzYQ_TXOyygR2BDggQfypa602r26u9JVn5CxJ8GtwdQ2pPn3lSH71dtKlRpFIoPPzDlnZmLunLr0iCVJdyQ9rPjoW2PLs7J45ROuGiNvJdlGy1cMA4kqQpnqhR4lAmH7bvT4J2HHnw4c-n987a3qL_eTqBKaOwf7EGQ7ElUAAJNREs6E5s5LwirCqiUJHKHFHfOBDp93oDbi9_oycitnqvvbN42gCc27l1svQiE2V-iem99Q-A12g-YCP7N2ZprjAH7Hz9yHRfxg1cQ9BvRy8pURFqol78NL6Mv-b9aCuLsSqGvuvVXN6LGuCc0JzWdHKOvm9tnAJ1lB0vLjbVa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