[LLVMbugs] [Bug 22834] New: False "Value stored is never read" due to reference captured in lambda

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 6 21:51:27 PST 2015


            Bug ID: 22834
           Summary: False "Value stored is never read" due to reference
                    captured in lambda
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: atwyman at dropbox.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14004
  --> http://llvm.org/bugs/attachment.cgi?id=14004&action=edit
Runnable example

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

/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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150307/9a852905/attachment.html>

More information about the llvm-bugs mailing list