<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117480>117480</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] missing thread safety annotations for std::unique_lock and std::shared_lock
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tamird
</td>
</tr>
</table>
<pre>
```c++
#include <mutex>
#include <shared_mutex>
class Foo {
int guard() {
std::lock_guard l(lock_);
return state_; // no warning
}
int unique() {
std::unique_lock l(lock_);
return state_; // warning: reading variable 'state_' requires holding shared_mutex 'lock_' [-Wthread-safety-analysis]
}
int shared() {
std::shared_lock l(lock_);
return state_; // warning: reading variable 'state_' requires holding shared_mutex 'lock_' [-Wthread-safety-analysis]
}
private:
int state_ __attribute__((guarded_by(lock_)));
std::shared_mutex lock_;
};
```
https://godbolt.org/z/hq7f9xT9K
Is there a reason these can't be annotated?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVEGPmzoQ_jXDZZQIBgLmwCF5eUhP71qpR2SwE9w69q5t0k1_fWVIutko0kq9FY0Ay9-Mv288M9x7dTRSNrDZwWaf8CmM1jWBn5QTSW_FpYEyXWwA2kVL95BugXJlBj0JiZD_c5qCfIP832d7fuROiu4BMr8Hzb3H1lqE6hoXEVGZgMeJOwHEgOqPm_HxQUC-hXyr7fC9m6Gogdi8BKohf3BwMkzOoA88yA7yHQK1QC0aiz-4M8oc3_FQ7T9SmYx6neSnXBZYFzn8GZkbk3yLTnKhzBHP3Cnea4lA1RVPFTr5OiknPY5Wz7D7FEfo9egKYbNbfQ1jDLfy_CDDZcUN1xevPGz2zzRHwUu4TwVfT_3LBSPii1NnHmRU9eHiFwLYdTwEp_opyK6bs8LmkpOi6y_3uhe7V_-Yq4Xw4nDDRSq__2-9dt8lYwgvPoaZs3a0orc6rK07ArU_gdrxtTrUb1_q_--d_vMYRukk8phbb01ceokDN0BVwF4iN8ZGhQLyNhFNLuq85olssiqnYpMyKpOxqbNM9GnBDrxkxLK-HmrBWDmUZV5sWN0nqqGUiiyjIiNKqVynKeurMmdFWrKSSgZFKk9c6bXW51OknSjvJ9lkWVWwNNG8l9rP84dIq_42ZYjiPHJN9Fr109FDkWrlg3-PE1TQ8-S6c9vs8aS8j0WylAEuZXBTq6zxeLDued9yI57WdzI53Tzcgwrj1K8HewJqI6XrZ_Xi7Dc5BKB21umB2qvUc0O_AgAA__-0NZ5d">