Skip to content

Commit f737729

Browse files
tkoeppezygoloid
authored andcommitted
P0806R2 Deprecate implicit capture of this via [=]
1 parent a22928a commit f737729

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

source/expressions.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,8 @@
13921392
the entity is said to be \defnx{implicitly captured}{capture!implicit}
13931393
by each intervening \grammarterm{lambda-expression} with an associated
13941394
\grammarterm{capture-default} that does not explicitly capture it.
1395+
The implicit capture of \tcode{*this} is deprecated when the
1396+
\grammarterm{capture-default} is \tcode{=}; see \ref{depr.capture.this}.
13951397
\begin{example}
13961398
\begin{codeblock}
13971399
void f(int, const int (&)[2] = {}); // \#1

source/future.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@
4848
\pnum
4949
The \grammarterm{noexcept-specifier} \tcode{throw()} is deprecated.
5050

51+
\rSec1[depr.capture.this]{Implicit capture of \tcode{*this} by reference}
52+
53+
\pnum
54+
For compatibility with prior \Cpp{} International Standards,
55+
a lambda expression with \grammarterm{capture-default}
56+
\tcode{=}\iref{expr.prim.lambda.capture} can implicitly capture
57+
\tcode{*this} by reference.
58+
\begin{example}
59+
\begin{codeblock}
60+
struct X {
61+
int x;
62+
void foo(int n) {
63+
auto f = [=]() { x = n; }; // deprecated: \tcode{x} means \tcode{this->x}, not a copy thereof
64+
auto g = [=, this]() { x = n; }; // recommended replacement
65+
}
66+
};
67+
\end{codeblock}
68+
\end{example}
69+
5170
\rSec1[depr.cpp.headers]{\Cpp{} standard library headers}
5271

5372
\pnum

0 commit comments

Comments
 (0)