https://bugs.llvm.org/show_bug.cgi?id=51674
Bug ID: 51674
Summary: False positive from clang-analyzer-deadcode.DeadStores
with reference and thread
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Static Analyzer
Assignee: dcough...@apple.com
Reporter: samuelmkear...@gmail.com
CC: dcough...@apple.com, llvm-bugs@lists.llvm.org
To reproduce: Install LLVM 14.0, add this minimal example as main.cpp:
```
#include <chrono>
#include <thread>
#include <iostream>
using namespace std::chrono_literals;
int main()
{
bool keep_running_thread = true;
std::thread thrd(
[](const bool& keep_running) {
while (keep_running)
{
std::cout << "Still running!\n";
std::this_thread::sleep_for(200ms);
}
},
std::ref(keep_running_thread));
std::this_thread::sleep_for(1s);
keep_running_thread = false;
thrd.join();
return 0;
}
```
Run clang-tidy --checks=clang-analyzer-* main.cpp. It reports:
main.cpp:22:3: warning: Value stored to 'keep_running_thread' is never read
[clang-analyzer-deadcode.DeadStores]
keep_running_thread = false;
^ ~~~~~
main.cpp:22:3: note: Value stored to 'keep_running_thread' is never read
keep_running_thread = false;
^ ~~~~~
I would expect no warning here since a reference to keep_running_thread is
passed to the thread.
Note: You can work around this by using a capturing lambda that captures
keep_running_thread by reference; but I would expect this to work using the
method shown as well.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs