Skip to content

[expr.prim.lambda] Move operator() return type description #4069

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

Closed
wants to merge 1 commit into from
Closed
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
59 changes: 36 additions & 23 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1574,18 +1574,6 @@
If a \grammarterm{lambda-expression} does not include a
\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were
\tcode{()}.
The lambda return type is \tcode{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}.
\begin{example}
\begin{codeblock}
auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int}
auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list}
int j;
auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&}
\end{codeblock}
\end{example}

\pnum
A lambda is a \defn{generic lambda}
Expand Down Expand Up @@ -1636,18 +1624,43 @@
The closure type for a \grammarterm{lambda-expression} has a public
inline function call operator (for a non-generic lambda) or
function call operator template (for a generic lambda)\iref{over.call}
whose parameters and return type
are described by the \grammarterm{lambda-expression}'s
\grammarterm{parameter-declaration-clause} and \grammarterm{trailing-return-type}
respectively, and whose
\grammarterm{template-parameter-list} consists of
the specified \grammarterm{template-parameter-list}, if any.
The \grammarterm{requires-clause} of the function call operator template
whose:
\begin{itemize}
\item \grammarterm{parameter-declaration-clause} is the \grammarterm{lambda-declarator}'s
\grammarterm{parameter-declaration-clause},

\item return type is \tcode{auto},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this isn't the return type, so much as it is the type in the decl-specifier-seq. (The declared return type is determined by the trailing-return-type if any, and the actual return type is what we deduce. Per [dcl.spec.auto.general]p3, the auto is just something that can appear in the decl-specifier-seq; it's not really a return type at all.) So:

Suggested change
\item return type is \tcode{auto},
\item \grammarterm{decl-specifier-seq} is the \grammarterm{lambda-declarator}'s \grammarterm{decl-specifier-seq} followed by \keyword{auto}, except that \keyword{constexpr} is also included if [...]

Also... should we say something about the attribute-specifier-seq?


\item \grammarterm{trailing-return-type} is the \grammarterm{lambda-declarator}'s
\grammarterm{trailing-return-type}, if any,

\item trailing \grammarterm{requires-clause} is the \grammarterm{lambda-declarator}'s
\grammarterm{requires-clause}, if any,

\item \grammarterm{template-parameter-list} is the \grammarterm{lambda-expression}'s
\grammarterm{template-parameter-list}, if any, and

\item \grammarterm{requires-clause} in the \grammarterm{template-head}
is the \grammarterm{requires-clause} immediately following
\tcode{<}~\grammarterm{template-parameter-list}{}~\tcode{>}, if any.
The trailing \grammarterm{requires-clause} of the function call operator
or operator template is the \grammarterm{requires-clause}
of the \grammarterm{lambda-declarator}, if any.
\tcode{<}~\grammarterm{template-parameter-list}{}~\tcode{>}
in the \grammarterm{lambda-expression}, if any.

\end{itemize}

\begin{note}
The actual return type will be 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}.
\begin{example}
\begin{codeblock}
auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int}
auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list}
int j;
auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&}
\end{codeblock}
\end{example}
\end{note}

\begin{note}
The function call operator template for a generic lambda might be
an abbreviated function template\iref{dcl.fct}.
Expand Down