Skip to content

Commit 4ea3604

Browse files
committed
[expr.prim.lambda] Split specification of lambda expressions into subsections.
Fixes #1155.
1 parent 37c76cb commit 4ea3604

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

source/expressions.tex

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,35 @@
706706
The type of the \grammarterm{lambda-expression} (which is also the type of the
707707
closure object) is a unique, unnamed non-union class type
708708
--- called the \defn{closure type} ---
709-
whose properties are described below.
710-
This class type is not an aggregate type~(\ref{dcl.init.aggr}).
709+
whose properties are described in section~\ref{expr.prim.lambda.closure}.
710+
711+
\pnum
712+
If a \grammarterm{lambda-expression} does not include a
713+
\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were
714+
\tcode{()}.
715+
The lambda return type is \tcode{auto}, which is replaced by the
716+
type specified by the
717+
\grammarterm{trailing-return-type} if provided and/or deduced from
718+
\tcode{return} statements as described in~\ref{dcl.spec.auto}.
719+
\begin{example}
720+
\begin{codeblock}
721+
auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int}
722+
auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list}
723+
int j;
724+
auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&}
725+
\end{codeblock}
726+
\end{example}
727+
728+
\rSec3[expr.prim.lambda.closure]{Closure types}%
729+
730+
\pnum
711731
The closure type is declared in the smallest block
712732
scope, class scope, or namespace scope that contains the corresponding
713733
\grammarterm{lambda-expression}. \begin{note} This determines the set of namespaces and
714734
classes associated with the closure type~(\ref{basic.lookup.argdep}). The parameter
715735
types of a \grammarterm{lambda-declarator} do not affect these associated namespaces and
716-
classes. \end{note} An implementation may define the closure type differently from what
736+
classes. \end{note} The closure type is not an aggregate type~(\ref{dcl.init.aggr}).
737+
An implementation may define the closure type differently from what
717738
is described below provided this does not alter the observable behavior of the program
718739
other than by changing:
719740

@@ -731,23 +752,6 @@
731752
An implementation shall not add members of rvalue reference type to the closure
732753
type.
733754

734-
\pnum
735-
If a \grammarterm{lambda-expression} does not include a
736-
\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were
737-
\tcode{()}.
738-
The lambda return type is \tcode{auto}, which is replaced by the
739-
type specified by the
740-
\grammarterm{trailing-return-type} if provided and/or deduced from
741-
\tcode{return} statements as described in~\ref{dcl.spec.auto}.
742-
\begin{example}
743-
\begin{codeblock}
744-
auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int}
745-
auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list}
746-
int j;
747-
auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&}
748-
\end{codeblock}
749-
\end{example}
750-
751755
\pnum
752756
The closure type for a non-generic \grammarterm{lambda-expression} has a public
753757
inline function call operator~(\ref{over.call}) whose parameters and return type
@@ -788,7 +792,9 @@
788792
q(); // OK: outputs \tcode{1a3.14}
789793
\end{codeblock}
790794
\end{example}
791-
This function call operator or operator template is declared
795+
796+
\pnum
797+
The function call operator or operator template is declared
792798
\tcode{const}~(\ref{class.mfct.non-static}) if and only if the
793799
\grammarterm{lambda-expression}'s \grammarterm{parameter-declaration-clause} is not
794800
followed by \tcode{mutable}. It is neither virtual nor declared \tcode{volatile}. Any
@@ -839,6 +845,8 @@
839845
the pointer to function shall behave as if it were a
840846
\grammarterm{decltype-specifier} denoting the return type of the corresponding
841847
function call operator template specialization.
848+
849+
\pnum
842850
\begin{note}
843851
If the generic lambda has no \grammarterm{trailing-return-type} or
844852
the \grammarterm{trailing-return-type} contains a placeholder type, return type
@@ -889,6 +897,7 @@
889897
\end{codeblock}
890898
\end{example}
891899

900+
\pnum
892901
The value returned by any given specialization of this conversion function
893902
template is the address of a function \tcode{F} that, when invoked, has the same
894903
effect as invoking the generic lambda's corresponding function call operator
@@ -908,6 +917,7 @@
908917
\end{codeblock}
909918
\end{example}
910919

920+
\pnum
911921
The conversion function or conversion function template is public,
912922
constexpr, non-virtual, non-explicit, const, and has a non-throwing exception
913923
specification~(\ref{except.spec}).
@@ -950,6 +960,25 @@
950960
the \grammarterm{compound-statement} of the \grammarterm{lambda-expression},
951961
with semantics as described in~\ref{dcl.fct.def.general}.
952962

963+
\pnum
964+
The closure type associated with a \grammarterm{lambda-expression} has no
965+
default constructor and a deleted copy assignment operator. It has a
966+
defaulted copy constructor and a defaulted move constructor~(\ref{class.copy}).
967+
\begin{note} These special member functions are implicitly defined as
968+
usual, and might therefore be defined as deleted. \end{note}
969+
970+
\pnum
971+
The closure type associated with a \grammarterm{lambda-expression} has an
972+
implicitly-declared destructor~(\ref{class.dtor}).
973+
974+
\pnum
975+
A member of a closure type shall not be
976+
explicitly instantiated~(\ref{temp.explicit}),
977+
explicitly specialized~(\ref{temp.expl.spec}), or
978+
named in a \tcode{friend} declaration~(\ref{class.friend}).
979+
980+
\rSec3[expr.prim.lambda.capture]{Captures}%
981+
953982
\pnum
954983
If a \grammarterm{lambda-capture} includes a \grammarterm{capture-default} that
955984
is \tcode{\&}, no identifier in a \grammarterm{simple-capture} of that
@@ -1263,23 +1292,6 @@
12631292
\end{codeblock}
12641293
\end{example}
12651294

1266-
\pnum
1267-
The closure type associated with a \grammarterm{lambda-expression} has no
1268-
default constructor and a deleted copy assignment operator. It has a
1269-
defaulted copy constructor and a defaulted move constructor~(\ref{class.copy}).
1270-
\begin{note} These special member functions are implicitly defined as
1271-
usual, and might therefore be defined as deleted. \end{note}
1272-
1273-
\pnum
1274-
The closure type associated with a \grammarterm{lambda-expression} has an
1275-
implicitly-declared destructor~(\ref{class.dtor}).
1276-
1277-
\pnum
1278-
A member of a closure type shall not be
1279-
explicitly instantiated~(\ref{temp.explicit}),
1280-
explicitly specialized~(\ref{temp.expl.spec}), or
1281-
named in a \tcode{friend} declaration~(\ref{class.friend}).
1282-
12831295
\pnum
12841296
When the \grammarterm{lambda-expression} is evaluated, the entities that are
12851297
captured by copy are used to direct-initialize each corresponding non-static data member

0 commit comments

Comments
 (0)