[llvm-bugs] [Bug 31977] New: Spurious -Wunused-lambda-capture for RAII object (e.g. reference-counted pointer)
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Feb 15 15:41:54 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=31977
Bug ID: 31977
Summary: Spurious -Wunused-lambda-capture for RAII object (e.g.
reference-counted pointer)
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: dholbert at mozilla.com
CC: llvm-bugs at lists.llvm.org
I've just tried building Firefox with tip-of-trunk clang today (rev 295219),
but I'm getting a bunch of -Wunused-lambda-capture build warnings for a
perfectly-reasonable code pattern.
In particular:
- Firefox's source code uses a RAII "RefPtr" struct to manage
reference-counted pointers
- We have a common pattern where we lambda-capture a RefPtr to a resource, for
the duration of a lambda which e.g. operates on some member variables of that
resource.
- The lambda-captured RefPtr may not be used, but we depend on it being
captured to keep the resource (and its mebmer-vars, data, whatever) alive so
that the lambda can safely operate on them.
Would it be possible to soften -Wunused-lambda-capture so that it doesn't warn
for this case? This seems like a handy warning, but we'll probably have to
disable it for the Firefox build process if it stays in its current state.
Here's some sample code that triggers this issue (using printf instead of
reference counting in the contstuctor/destructor):
////////////////////
#include <stdio.h>
struct MyRaiiThing {
MyRaiiThing() {
printf("Constructing MyRaiiThing\n");
}
MyRaiiThing(const MyRaiiThing& other) {
printf("Copy-constructing MyRaiiThing\n");
}
~MyRaiiThing() {
printf("Destructing MyRaiiThing\n");
}
};
int main() {
MyRaiiThing thing;
auto lambda = []() {
printf("Inside lambda\n");
};
lambda();
}
--
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/20170215/a0adc059/attachment.html>
More information about the llvm-bugs
mailing list