asl/llvm-bugzilla

Thread Safety Analysis: false positive on const auto scoped_lock variable (Bugzilla Bug 3)

Opened this issue · 1 comments

asl commented

This issue was created automatically with bugzilla2github

Bugzilla Bug 3

Date: 2019-10-27T10:17:29+07:00
From: @adrianimboden
To: Unassigned Clang Bugs <unassignedclangbugs@nondot.org>
CC: llvm-bugs@lists.llvm.org, neeilans@live.com, @zygoloid

Last updated: 2019-10-27T10:17:29+07:00

asl commented

Comment 190270

Date: 2019-10-27 10:17:29 -0700
From: @adrianimboden

$ cat main.cpp 
#include 

static std::mutex guard;

int main() { const auto lock = std::scoped_lock{guard}; }



$ clang++ -std=c++17 -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Wthread-safety main.cpp 
main.cpp:5:57: warning: releasing mutex 'lock' that was not held [-Wthread-safety-analysis]
int main() { const auto lock = std::scoped_lock{guard}; }
                                                        ^
1 warning generated.



when the variable is "auto lock" instead of "const auto lock", then no warning is generated.