Skip to content

Commit c466138

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

File tree

5 files changed

+57
-45
lines changed

5 files changed

+57
-45
lines changed

source/basic.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@
36503650
has all of the following properties:
36513651
\begin{itemize}
36523652
\item it has a trivial destructor,
3653-
\item it is either a closure type~(\ref{expr.prim.lambda}),
3653+
\item it is either a closure type~(\ref{expr.prim.lambda.closure}),
36543654
an aggregate type~(\ref{dcl.init.aggr}), or
36553655
has at least one constexpr constructor or constructor template
36563656
(possibly inherited~(\ref{namespace.udecl}) from a base class)

source/declarations.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@
15681568
from an initializer. The \tcode{auto}
15691569
\grammarterm{type-specifier} is also used to
15701570
introduce a function type having a \grammarterm{trailing-return-type} or to
1571-
signify that a lambda is a generic lambda (\ref{expr.prim.lambda}).
1571+
signify that a lambda is a generic lambda (\ref{expr.prim.lambda.closure}).
15721572
The \tcode{auto} \grammarterm{type-specifier} is also used to introduce a
15731573
decomposition declaration (\ref{dcl.decomp}).
15741574

@@ -1590,7 +1590,7 @@
15901590
\grammarterm{decl-specifier}{s} in the \grammarterm{decl-specifier-seq} of a
15911591
\grammarterm{parameter-declaration} of a \grammarterm{lambda-expression}, the
15921592
\indextext{generic lambda!definition of}%
1593-
lambda is a \term{generic lambda}~(\ref{expr.prim.lambda}). \begin{example}
1593+
lambda is a \term{generic lambda}~(\ref{expr.prim.lambda.closure}). \begin{example}
15941594
\begin{codeblock}
15951595
auto glambda = [](int i, auto a) { return i; }; // OK: a generic lambda
15961596
\end{codeblock}

source/expressions.tex

Lines changed: 51 additions & 39 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
@@ -4985,7 +4997,7 @@
49854997
If the odr-use occurs in an invocation
49864998
of a function call operator of a closure type,
49874999
it no longer refers to \tcode{this} or to an enclosing automatic variable
4988-
due to the transformation~(\ref{expr.prim.lambda})
5000+
due to the transformation~(\ref{expr.prim.lambda.capture})
49895001
of the \grammarterm{id-expression} into
49905002
an access of the corresponding data member.
49915003
\begin{example}

source/special.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@
518518
The first context is when a default constructor is called to initialize
519519
an element of an array with no corresponding initializer~(\ref{dcl.init}).
520520
The second context is when a copy constructor is called to copy an element of
521-
an array while the entire array is copied~(\ref{expr.prim.lambda},~\ref{class.copy}).
521+
an array while the entire array is copied~(\ref{expr.prim.lambda.capture},~\ref{class.copy}).
522522
In either case, if the constructor has one or more default arguments,
523523
the destruction of every temporary created in a default argument is
524524
sequenced before the construction of the next array element, if any.

source/templates.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
in a templated entity,
149149
\item a member of a templated entity,
150150
\item an enumerator for an enumeration that is a templated entity, or
151-
\item the closure type of a \grammarterm{lambda-expression}~(\ref{expr.prim.lambda})
151+
\item the closure type of a \grammarterm{lambda-expression}~(\ref{expr.prim.lambda.closure})
152152
appearing in the declaration of a templated entity.
153153
\end{itemize}
154154

@@ -4836,7 +4836,7 @@
48364836
the same template parameters and the same access as that of the function template
48374837
\tcode{f}
48384838
used at that point, except that the scope in which a closure type is
4839-
declared~(\ref{expr.prim.lambda}) -- and therefore its associated namespaces --
4839+
declared~(\ref{expr.prim.lambda.closure}) -- and therefore its associated namespaces --
48404840
remain as determined from the context of the definition for the default
48414841
argument.
48424842
This analysis is called

0 commit comments

Comments
 (0)