[LLVMbugs] [Bug 12566] New: need warning for capturing and storing a ref to a local in lambda

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 16 10:00:32 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12566

             Bug #: 12566
           Summary: need warning for capturing and storing a ref to a
                    local in lambda
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: mitchnull+llvm at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following code should produce a warning for capturing and returning a ref
to the local n in foo():

#include <functional>

std::function<int()>
foo(int n) {
    return [&]{ return n; };
}

int main() {
    auto f = foo(5);
    return f();
}

similar to the warning given when returning a pointer to a local:

warning: address of stack memory associated with local variable
      'n' returned [-Wreturn-stack-address]
    return &n;

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list