Created on 2009-09-04.00:00:00 last changed 130 months ago
[Moved to DR status at the April, 2013 meeting as part of paper N3638.]
Additional note (February, 2012):
EWG requested that the adoption of this proposed resolution be postponed to allow them to discuss it. The issue has thus been returned to "review" status pending EWG action.
Proposed resolution (August, 2011):
Change 7.5.6 [expr.prim.lambda] paragraph 4 as follows:
...If a lambda-expression does not include a trailing-return-type, it is as if the trailing-return-type denotes the following type:
if the compound-statement is of the form
{ attribute-specifier-seqopt return expression ;
the type of the returned expression after lvalue-to-rvalue conversion (7.3.2 [conv.lval]), array-to-pointer conversion (7.3.3 [conv.array]), and function-to-pointer conversion (7.3.4 [conv.func]);
otherwise, void.if there are no return statements in the compound-statement, or all return statements return either an expression of type void or no expression or braced-init-list, the type void;
otherwise, if all return statements return an expression and the types of the returned expressions after lvalue-to-rvalue conversion (7.3.2 [conv.lval]), array-to-pointer conversion (7.3.3 [conv.array]), and function-to-pointer conversion (7.3.4 [conv.func]) are the same, that common type;
otherwise, the program is ill-formed.
[Example:
auto x1 = [](int i){ return i; }; // OK: return type is int auto x2 = []{ return { 1, 2 }; }; // error: the return type is void (a // braced-init-list is not an expression) struct A { int fn1(); const int& fn2(); }; template <class T> void f () { [](T t, bool b){ if (b) return t.fn1(); else return t.fn2(); }; } template void f<A>(); // OK: lambda return type is int—end example]
There does not appear to be any technical difficulty that would require the current restriction that the return type of a lambda can be deduced only if the body of the lambda consists of a single return statement. In particular, multiple return statements could be permitted if they all return the same type.
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-03-03 00:00:00 | admin | set | status: drwp -> cd3 |
2013-10-14 00:00:00 | admin | set | status: dr -> drwp |
2013-05-03 00:00:00 | admin | set | messages: + msg4379 |
2013-05-03 00:00:00 | admin | set | status: review -> dr |
2012-02-27 00:00:00 | admin | set | messages: + msg3749 |
2012-02-27 00:00:00 | admin | set | status: ready -> review |
2011-09-06 00:00:00 | admin | set | messages: + msg3430 |
2011-09-06 00:00:00 | admin | set | status: open -> ready |
2009-09-04 00:00:00 | admin | create |