Skip to content

Commit b814dcf

Browse files
committed
[expr.prim.lambda] Split specification of lambda expressions into subsections.
Fixes #1155.
1 parent 2f3c3b8 commit b814dcf

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
@@ -3630,7 +3630,7 @@
36303630
has all of the following properties:
36313631
\begin{itemize}
36323632
\item it has a trivial destructor,
3633-
\item it is either a closure type~(\ref{expr.prim.lambda}),
3633+
\item it is either a closure type~(\ref{expr.prim.lambda.closure}),
36343634
an aggregate type~(\ref{dcl.init.aggr}), or
36353635
has at least one constexpr constructor or constructor template
36363636
(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
@@ -1556,7 +1556,7 @@
15561556
from an initializer. The \tcode{auto}
15571557
\grammarterm{type-specifier} is also used to
15581558
introduce a function type having a \grammarterm{trailing-return-type} or to
1559-
signify that a lambda is a generic lambda (\ref{expr.prim.lambda}).
1559+
signify that a lambda is a generic lambda (\ref{expr.prim.lambda.closure}).
15601560
The \tcode{auto} \grammarterm{type-specifier} is also used to introduce a
15611561
decomposition declaration (\ref{dcl.decomp}).
15621562

@@ -1578,7 +1578,7 @@
15781578
\grammarterm{decl-specifier}{s} in the \grammarterm{decl-specifier-seq} of a
15791579
\grammarterm{parameter-declaration} of a \grammarterm{lambda-expression}, the
15801580
\indextext{generic lambda!definition of}%
1581-
lambda is a \term{generic lambda}~(\ref{expr.prim.lambda}). \begin{example}
1581+
lambda is a \term{generic lambda}~(\ref{expr.prim.lambda.closure}). \begin{example}
15821582
\begin{codeblock}
15831583
auto glambda = [](int i, auto a) { return i; }; // OK: a generic lambda
15841584
\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
@@ -1258,23 +1287,6 @@
12581287
\end{codeblock}
12591288
\end{example}
12601289

1261-
\pnum
1262-
The closure type associated with a \grammarterm{lambda-expression} has no
1263-
default constructor and a deleted copy assignment operator. It has a
1264-
defaulted copy constructor and a defaulted move constructor~(\ref{class.copy}).
1265-
\begin{note} These special member functions are implicitly defined as
1266-
usual, and might therefore be defined as deleted. \end{note}
1267-
1268-
\pnum
1269-
The closure type associated with a \grammarterm{lambda-expression} has an
1270-
implicitly-declared destructor~(\ref{class.dtor}).
1271-
1272-
\pnum
1273-
A member of a closure type shall not be
1274-
explicitly instantiated~(\ref{temp.explicit}),
1275-
explicitly specialized~(\ref{temp.expl.spec}), or
1276-
named in a \tcode{friend} declaration~(\ref{class.friend}).
1277-
12781290
\pnum
12791291
When the \grammarterm{lambda-expression} is evaluated, the entities that are
12801292
captured by copy are used to direct-initialize each corresponding non-static data member
@@ -4980,7 +4992,7 @@
49804992
If the odr-use occurs in an invocation
49814993
of a function call operator of a closure type,
49824994
it no longer refers to \tcode{this} or to an enclosing automatic variable
4983-
due to the transformation~(\ref{expr.prim.lambda})
4995+
due to the transformation~(\ref{expr.prim.lambda.capture})
49844996
of the \grammarterm{id-expression} into
49854997
an access of the corresponding data member.
49864998
\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

@@ -4808,7 +4808,7 @@
48084808
the same template parameters and the same access as that of the function template
48094809
\tcode{f}
48104810
used at that point, except that the scope in which a closure type is
4811-
declared~(\ref{expr.prim.lambda}) -- and therefore its associated namespaces --
4811+
declared~(\ref{expr.prim.lambda.closure}) -- and therefore its associated namespaces --
48124812
remain as determined from the context of the definition for the default
48134813
argument.
48144814
This analysis is called

0 commit comments

Comments
 (0)