False "Value stored is never read" due to reference captured in lambda
| Bugzilla Link | 22834 |
| Resolution | FIXED |
| Resolved on | Aug 04, 2020 14:38 |
| Version | 3.5 |
| OS | MacOS X |
| Attachments | Runnable example |
| Reporter | LLVM Bugzilla Contributor |
| CC | @aaronpuchert,@devincoughlin,@haoNoQ,@Xazax-hun |
| Fixed by commit(s) | r253630 |
Extended Description
If a value is captured in a lambda, then modified later in the code, the analyzer thinks the value is never used, and flags it as a dead store, even if the lambda is run locally to use the value. Here's a simple example, where f1() prints "0" rather than "1" as a result of the indicated line.
bool b = true;
auto f1 = [&b] () {
cout << b << endl;
};
b = false; // warning on this line
f1();
/ws/art_hack/ArtCppHack/ArtCppHack/main.cpp:12:5: warning: Value stored to 'b' is never read b = false; ^ ~~~~~ 1 warning generated.
We're generally able to work around this by adding something like "(void)b;" to make the variable appear to be used, but it would be nice not to have to.
I'm using the analyzer integrated in Xcode 6.1.1.
I hope so. Lambdas are much more popular these days than they were in 2015 and i haven't heard much complaints about those recently. Tried to reproduce it on Godbolt: the false positive is there until 3.7.1, and the supposed fix was first released with 3.8. So it all adds up.
I hope so. Lambdas are much more popular these days than they were in 2015 and i haven't heard much complaints about those recently.
Patch under review. http://reviews.llvm.org/D14736 This has been submitted, so I assume the bug can be closed?
Patch under review. http://reviews.llvm.org/D14736
assigned to @tkremenek