Skip to content

P2173R1 Attributes on lambda-expressions #5273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8600,12 +8600,11 @@
dependency propagation into and out of functions.
No
\grammarterm{attribute-argument-clause} shall be present. The attribute may be
applied to the \grammarterm{declarator-id} of a
\grammarterm{parameter-declaration} in a function declaration or lambda, in
applied to a parameter of a function or lambda, in
which case it specifies that the initialization of the parameter carries a
dependency to\iref{intro.multithread} each lvalue-to-rvalue
conversion\iref{conv.lval} of that object. The attribute may also be applied
to the \grammarterm{declarator-id} of a function declaration, in which case it
to a function or a lambda call operator, in which case it
specifies that the return value, if any, carries a dependency to the evaluation
of the function call expression.

Expand Down Expand Up @@ -8894,8 +8893,8 @@

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

Expand Down Expand Up @@ -8985,9 +8984,9 @@

\pnum
The \grammarterm{attribute-token} \tcode{noreturn} specifies that a function does not return.
No
\grammarterm{attribute-argument-clause} shall be present. The attribute may be applied to the
\grammarterm{declarator-id} in a function declaration. The first declaration of a function shall
No \grammarterm{attribute-argument-clause} shall be present.
The attribute may be applied to a function or a lambda call operator.
The first declaration of a function shall
specify the \tcode{noreturn} attribute if any declaration of that function specifies the
\tcode{noreturn} attribute. If a function is declared with the \tcode{noreturn} attribute in one
translation unit and the same function is declared without the \tcode{noreturn} attribute in another
Expand Down
50 changes: 34 additions & 16 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1673,8 +1673,9 @@

\begin{bnf}
\nontermdef{lambda-expression}\br
lambda-introducer lambda-declarator compound-statement\br
lambda-introducer \terminal{<} template-parameter-list \terminal{>} \opt{requires-clause} lambda-declarator compound-statement
lambda-introducer \opt{attribute-specifier-seq} lambda-declarator compound-statement\br
lambda-introducer \terminal{<} template-parameter-list \terminal{>} \opt{requires-clause} \opt{attribute-specifier-seq}\br
\bnfindent lambda-declarator compound-statement
\end{bnf}

\begin{bnf}
Expand All @@ -1684,13 +1685,11 @@

\begin{bnf}
\nontermdef{lambda-declarator}\br
lambda-specifiers\br
\terminal{(} parameter-declaration-clause \terminal{)} lambda-specifiers \opt{requires-clause}
\end{bnf}

\begin{bnf}
\nontermdef{lambda-specifiers}\br
\opt{lambda-specifier-seq} \opt{noexcept-specifier} \opt{attribute-specifier-seq} \opt{trailing-return-type}
lambda-specifier-seq \opt{noexcept-specifier} \opt{attribute-specifier-seq} \opt{trailing-return-type}\br
noexcept-specifier \opt{attribute-specifier-seq} \opt{trailing-return-type}\br
\opt{trailing-return-type}\br
\terminal{(} parameter-declaration-clause \terminal{)} \opt{lambda-specifier-seq} \opt{noexcept-specifier} \opt{attribute-specifier-seq}\br
\bnfindent \opt{trailing-return-type} \opt{requires-clause}
\end{bnf}

\begin{bnf}
Expand Down Expand Up @@ -1727,6 +1726,20 @@
object\iref{function.objects}.
\end{note}

\pnum
An ambiguity can arise
because a \grammarterm{requires-clause} can end in
an \grammarterm{attribute-specifier-seq},
which collides with
the \grammarterm{attribute-specifier-seq} in \grammarterm{lambda-expression}.
In such cases,
any attributes are treated as
\grammarterm{attribute-specifier-seq} in \grammarterm{lambda-expression}.
\begin{note}
Such ambiguous cases cannot have valid semantics
because the constraint expression would not have type \keyword{bool}.
\end{note}

\pnum
A \grammarterm{lambda-specifier-seq}
shall contain at most one of each \grammarterm{lambda-specifier} and
Expand All @@ -1740,13 +1753,15 @@
\end{note}

\pnum
If a \grammarterm{lambda-expression} includes an empty
\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were
\tcode{()}.
The lambda return type is \keyword{auto}, which is replaced by the
type specified by the
\grammarterm{trailing-return-type} if provided and/or deduced from
\tcode{return} statements as described in~\ref{dcl.spec.auto}.
If a \grammarterm{lambda-declarator} does not include
a \grammarterm{parameter-declaration-clause},
it is as if \tcode{()} were inserted
at the start of the \grammarterm{lambda-declarator}.
If the \grammarterm{lambda-declarator}
does not include a \grammarterm{trailing-return-type},
the lambda return type is \keyword{auto},
which is deduced from \keyword{return} statements
as described in \ref{dcl.spec.auto}.
\begin{example}
\begin{codeblock}
auto x1 = [](int i) { return i; }; // OK, return type is \tcode{int}
Expand Down Expand Up @@ -1888,6 +1903,9 @@
applies to the corresponding function call operator or operator template.
An \grammarterm{attribute-specifier-seq} in a \grammarterm{lambda-declarator} appertains
to the type of the corresponding function call operator or operator template.
An \grammarterm{attribute-specifier-seq} in a \grammarterm{lambda-expression}
preceding a \grammarterm{lambda-declarator}
appertains to the corresponding function call operator or operator template.
The function call operator or any given operator template specialization
is a constexpr function if either
the corresponding \grammarterm{lambda-expression}{'s}
Expand Down