diff --git a/cppguide.html b/cppguide.html index bbf1f64..761194c 100644 --- a/cppguide.html +++ b/cppguide.html @@ -3479,7 +3479,8 @@ array(T, U...) -> std::array<T, 1 + sizeof...(U)>;
Use lambda expressions where appropriate. Prefer explicit captures -when the lambda will escape the current scope.
+when the lambda will escape the current scope. Do not use[=]
+or [=, this]
to capture this
.
Lambda expressions are a concise way of creating anonymous @@ -3555,13 +3556,19 @@ std::sort(indices.begin(), indices.end(), [&](int a, int b) {
[&]
) makes such bugs easier to introduce.
- [=]
) can be misleading because
+ it does not prevent dangling-pointer bugs. Capturing a pointer by value
+ doesn't cause a deep copy, so it has essentially the same lifetime issues
+ as capture by reference.this
along with default capture by value is
+ especially confusing, and strict support among C++ versions is incompatible.
+ If capturing this
(either explicitly or with by-reference
+ capture default), list any by-value captures explicitly. Keep in mind that
+ uses of captured this
are often implicit.