Skip to content

[Bug]: thread-safety analysis false positive for trivial scope in for-each #1901

@MBkkt

Description

@MBkkt

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 () {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions