Describe the issue
thread-safety analysis false positive for trivial scope in for-each.
Probably bug in clang...
Steps to reproduce the problem
https://godbolt.org/z/W1vaPce63
What version of Abseil are you using?
latest
What operating system and version are you using?
linux
What compiler and version are you using?
clang 20
What build system are you using?
cmake
Additional context
<source>:9:1: error: mutex 'm' is still held at the end of function [-Werror,-Wthread-safety-analysis]
9 | }
| ^
<source>:6:26: note: mutex acquired here
6 | for (absl::MutexLock lock{&m}; int& x : data) {
| ^
#include <absl/synchronization/mutex.h>
void bar(int&);
void foo_for(absl::Mutex& m, std::span<int> data) {
for (absl::MutexLock lock{&m}; int& x : data) {
bar(x);
}
}
int main () {}