diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 3be01b8..06dde4f 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2385,7 +2385,7 @@ Other function rules: * [F.51: Where there is a choice, prefer default arguments over overloading](#Rf-default-args) * [F.52: Prefer capturing by reference in lambdas that will be used locally, including passed to algorithms](#Rf-reference-capture) * [F.53: Avoid capturing by reference in lambdas that will be used non-locally, including returned, stored on the heap, or passed to another thread](#Rf-value-capture) -* [F.54: If you capture `this`, capture all variables explicitly (no default capture)](#Rf-this-capture) +* [F.54: When writing a lambda that captures `this` or any class data member, don't use `[=]` default capture](#Rf-this-capture) * [F.55: Don't use `va_arg` arguments](#F-varargs) * [F.56: Avoid unnecessary condition nesting](#F-nesting) @@ -4118,7 +4118,7 @@ If the `this` pointer must be captured, consider using `[*this]` capture, which * (Simple) Warn when capture-list contains a reference to a locally declared variable * (Complex) Flag when capture-list contains a reference to a locally declared variable and the lambda is passed to a non-`const` and non-local context -### F.54: If you capture `this`, capture all variables explicitly (no default capture) +### F.54: When writing a lambda that captures `this` or any class data member, don't use `[=]` default capture ##### Reason @@ -4154,11 +4154,11 @@ It's confusing. Writing `[=]` in a member function appears to capture by value, ##### Note -This is under active discussion in standardization, and might be addressed in a future version of the standard by adding a new capture mode or possibly adjusting the meaning of `[=]`. For now, just be explicit. +If you intend to capture a copy of all class data members, consider C++17 `[*this]`. ##### Enforcement -* Flag any lambda capture-list that specifies a capture-default (e.g., `=` or `&`) and also captures `this` (whether explicitly such as `[&, this]` or via default capture such as `[=]` and a use of `this` in the body) +* Flag any lambda capture-list that specifies a capture-default of `[=]` and also captures `this` (whether explicitly or via the default capture and a use of `this` in the body) ### F.55: Don't use `va_arg` arguments @@ -19760,7 +19760,7 @@ Additions to `std` might clash with future versions of the standard. }; } - namespace Foo { // GOOD: user namespace is allowed + namespace Foo { // GOOD: user namespace is allowed class My_vector { // . . . };