Warning for unused lambda captures

I would like to add a warning for lambdas that explicitly capture
variables that they don't use.

e.g.
int i = 3;
auto f = [&i] { return 5; };

This is similar to Wunused-private-field. I propose the flag
-Wunused-lambda-capture.

Comments?

I would like to add a warning for lambdas that explicitly capture
variables that they don't use.

e.g.
int i = 3;
auto f = [&i] { return 5; };

This is similar to Wunused-private-field. I propose the flag
-Wunused-lambda-capture.

Comments?

I think this could be a useful warning for explicit captures. It seems
possible that someone may want to capture something by value purely
for its RAII properties, but that seems unlikely to be common and
could still be silenced with an explicit cast to void?

~Aaron

It looks like -Wunused-private-field checks
InitializationHasSideEffects(FieldDecl&) to avoid warning about such
fields.

I think this could be a useful warning for explicit captures. It seems
possible that someone may want to capture something by value purely
for its RAII properties, but that seems unlikely to be common and
could still be silenced with an explicit cast to void?

It looks like -Wunused-private-field checks
InitializationHasSideEffects(FieldDecl&) to avoid warning about such
fields.

Perfect! I figured we already had a solution for it, I just wanted to
point it out as a possible false-positive to avoid. I think it's a
great idea for a diagnostic in Clang.

~Aaron

I think this could be a useful warning for explicit captures. It seems
possible that someone may want to capture something by value purely
for its RAII properties, but that seems unlikely to be common and
could still be silenced with an explicit cast to void?

It looks like -Wunused-private-field checks
InitializationHasSideEffects(FieldDecl&) to avoid warning about such
fields.

Perfect! I figured we already had a solution for it, I just wanted to
point it out as a possible false-positive to avoid. I think it's a
great idea for a diagnostic in Clang.

Sounds like a great idea. I'd be keen to use this check and happy to review a patch.

Yep, good idea.