Skip to content

Commit 9eb9a1e

Browse files
authored
Merge 2022-02 CWG Motion 2
P2173R1 Attributes on lambda-expressions
2 parents 21dc0d3 + ff0882b commit 9eb9a1e

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

source/declarations.tex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8600,12 +8600,11 @@
86008600
dependency propagation into and out of functions.
86018601
No
86028602
\grammarterm{attribute-argument-clause} shall be present. The attribute may be
8603-
applied to the \grammarterm{declarator-id} of a
8604-
\grammarterm{parameter-declaration} in a function declaration or lambda, in
8603+
applied to a parameter of a function or lambda, in
86058604
which case it specifies that the initialization of the parameter carries a
86068605
dependency to\iref{intro.multithread} each lvalue-to-rvalue
86078606
conversion\iref{conv.lval} of that object. The attribute may also be applied
8608-
to the \grammarterm{declarator-id} of a function declaration, in which case it
8607+
to a function or a lambda call operator, in which case it
86098608
specifies that the return value, if any, carries a dependency to the evaluation
86108609
of the function call expression.
86118610

@@ -8894,8 +8893,8 @@
88948893

88958894
\pnum
88968895
The \grammarterm{attribute-token} \tcode{nodiscard}
8897-
may be applied to the \grammarterm{declarator-id}
8898-
in a function declaration or to the declaration of a class or enumeration.
8896+
may be applied to a function or a lambda call operator or
8897+
to the declaration of a class or enumeration.
88998898
An \grammarterm{attribute-argument-clause} may be present
89008899
and, if present, shall have the form:
89018900

@@ -8985,9 +8984,9 @@
89858984

89868985
\pnum
89878986
The \grammarterm{attribute-token} \tcode{noreturn} specifies that a function does not return.
8988-
No
8989-
\grammarterm{attribute-argument-clause} shall be present. The attribute may be applied to the
8990-
\grammarterm{declarator-id} in a function declaration. The first declaration of a function shall
8987+
No \grammarterm{attribute-argument-clause} shall be present.
8988+
The attribute may be applied to a function or a lambda call operator.
8989+
The first declaration of a function shall
89918990
specify the \tcode{noreturn} attribute if any declaration of that function specifies the
89928991
\tcode{noreturn} attribute. If a function is declared with the \tcode{noreturn} attribute in one
89938992
translation unit and the same function is declared without the \tcode{noreturn} attribute in another

source/expressions.tex

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,8 +1673,9 @@
16731673

16741674
\begin{bnf}
16751675
\nontermdef{lambda-expression}\br
1676-
lambda-introducer lambda-declarator compound-statement\br
1677-
lambda-introducer \terminal{<} template-parameter-list \terminal{>} \opt{requires-clause} lambda-declarator compound-statement
1676+
lambda-introducer \opt{attribute-specifier-seq} lambda-declarator compound-statement\br
1677+
lambda-introducer \terminal{<} template-parameter-list \terminal{>} \opt{requires-clause} \opt{attribute-specifier-seq}\br
1678+
\bnfindent lambda-declarator compound-statement
16781679
\end{bnf}
16791680

16801681
\begin{bnf}
@@ -1684,13 +1685,11 @@
16841685

16851686
\begin{bnf}
16861687
\nontermdef{lambda-declarator}\br
1687-
lambda-specifiers\br
1688-
\terminal{(} parameter-declaration-clause \terminal{)} lambda-specifiers \opt{requires-clause}
1689-
\end{bnf}
1690-
1691-
\begin{bnf}
1692-
\nontermdef{lambda-specifiers}\br
1693-
\opt{lambda-specifier-seq} \opt{noexcept-specifier} \opt{attribute-specifier-seq} \opt{trailing-return-type}
1688+
lambda-specifier-seq \opt{noexcept-specifier} \opt{attribute-specifier-seq} \opt{trailing-return-type}\br
1689+
noexcept-specifier \opt{attribute-specifier-seq} \opt{trailing-return-type}\br
1690+
\opt{trailing-return-type}\br
1691+
\terminal{(} parameter-declaration-clause \terminal{)} \opt{lambda-specifier-seq} \opt{noexcept-specifier} \opt{attribute-specifier-seq}\br
1692+
\bnfindent \opt{trailing-return-type} \opt{requires-clause}
16941693
\end{bnf}
16951694

16961695
\begin{bnf}
@@ -1727,6 +1726,20 @@
17271726
object\iref{function.objects}.
17281727
\end{note}
17291728

1729+
\pnum
1730+
An ambiguity can arise
1731+
because a \grammarterm{requires-clause} can end in
1732+
an \grammarterm{attribute-specifier-seq},
1733+
which collides with
1734+
the \grammarterm{attribute-specifier-seq} in \grammarterm{lambda-expression}.
1735+
In such cases,
1736+
any attributes are treated as
1737+
\grammarterm{attribute-specifier-seq} in \grammarterm{lambda-expression}.
1738+
\begin{note}
1739+
Such ambiguous cases cannot have valid semantics
1740+
because the constraint expression would not have type \keyword{bool}.
1741+
\end{note}
1742+
17301743
\pnum
17311744
A \grammarterm{lambda-specifier-seq}
17321745
shall contain at most one of each \grammarterm{lambda-specifier} and
@@ -1740,13 +1753,15 @@
17401753
\end{note}
17411754

17421755
\pnum
1743-
If a \grammarterm{lambda-expression} includes an empty
1744-
\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were
1745-
\tcode{()}.
1746-
The lambda return type is \keyword{auto}, which is replaced by the
1747-
type specified by the
1748-
\grammarterm{trailing-return-type} if provided and/or deduced from
1749-
\tcode{return} statements as described in~\ref{dcl.spec.auto}.
1756+
If a \grammarterm{lambda-declarator} does not include
1757+
a \grammarterm{parameter-declaration-clause},
1758+
it is as if \tcode{()} were inserted
1759+
at the start of the \grammarterm{lambda-declarator}.
1760+
If the \grammarterm{lambda-declarator}
1761+
does not include a \grammarterm{trailing-return-type},
1762+
the lambda return type is \keyword{auto},
1763+
which is deduced from \keyword{return} statements
1764+
as described in \ref{dcl.spec.auto}.
17501765
\begin{example}
17511766
\begin{codeblock}
17521767
auto x1 = [](int i) { return i; }; // OK, return type is \tcode{int}
@@ -1888,6 +1903,9 @@
18881903
applies to the corresponding function call operator or operator template.
18891904
An \grammarterm{attribute-specifier-seq} in a \grammarterm{lambda-declarator} appertains
18901905
to the type of the corresponding function call operator or operator template.
1906+
An \grammarterm{attribute-specifier-seq} in a \grammarterm{lambda-expression}
1907+
preceding a \grammarterm{lambda-declarator}
1908+
appertains to the corresponding function call operator or operator template.
18911909
The function call operator or any given operator template specialization
18921910
is a constexpr function if either
18931911
the corresponding \grammarterm{lambda-expression}{'s}

0 commit comments

Comments
 (0)