[llvm-bugs] [Bug 34865] New: Clang doesn't require references to be listed in lambda capture

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 6 12:30:55 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34865

            Bug ID: 34865
           Summary: Clang doesn't require references to be listed in
                    lambda capture
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: redbeard0531 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Clang will compile this faulty code without an error:

int var = 0;
int main() {
    int& varRef = var;
    return []{return varRef;}();
}

This also leads to an incorrect warning if varRef is correctly captured (which
is how we noticed this issue in the first place):

> clang++ test2.cpp --std=c++17 -Wall 
test2.cpp:4:14: warning: lambda capture 'varRef' is not required to be captured
for this use [-Wunused-lambda-capture]
    return [&varRef]{return varRef;}();
             ^


This is a reduced example from this real-world code:
https://github.com/mongodb/mongo/blob/r3.5.13/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp#L383-L402
(clang++-5.0 -Wall warns that kRsOplogNamespace is unused even though it is
used on line 402)

-- 
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/20171006/2b91bb3a/attachment.html>


More information about the llvm-bugs mailing list