r291905 - [Sema] Add warning for unused lambda captures

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 22 06:17:27 PST 2017

On 20 January 2017 at 21:32, Nico Weber <thakis at chromium.org> wrote:
> This warns about code like
>   constexpr int foo = 4;
>   [&foo]() { use(foo); }
> That's correct, but removing &foo then makes MSVC complain about this code
> like "error C3493: 'foo' cannot be implicitly captured because no default
> capture mode has been specified". A workaround is to make foo static const
> instead of constexpr.
> This seems like an MSVC bug, but it's still a bit annoying that clang now
> suggests doing things that won't build in other compilers. Any ideas what to
> do about this?

Should Clang care about the behaviour of other compilers that don't
follow the standard?

You could:
Disable the warning on the command line.
Disable the warning with a pragma.
Cast foo to void inside the lambda.
Only capture foo when building with MSVC.
Stop building with MSVC.
Complain to Microsoft.

Malcolm Parsons

More information about the cfe-commits mailing list