styleguide icon indicating copy to clipboard operation
styleguide copied to clipboard

C++: Do not use [=] or [=,this] to capture 'this'

Open pdillinger opened this issue 5 years ago • 1 comments

Summary: C++20 deprecates [=] capturing 'this' (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0806r2.html) but the recommended alternative [=,this] is not standards-legal prior to C++20 (though it is widely accepted with warning).

For portability (and readability), style should forbid using [=] or [=,this] to capture 'this'. Any by-value captures must be explicitly listed if also capturing 'this', though 'this' can still be implicitly default-captured by reference, as in [&, some_var_to_copy].

Test Plan: documentation only

pdillinger avatar Apr 14 '20 18:04 pdillinger

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Apr 14 '20 18:04 googlebot