Movatterモバイル変換


[0]ホーム

URL:


Issue 975 - WG21 CWG Issues
Title
Restrictions on return type deduction for lambdas
Status
cd3
Section
7.5.6 [expr.prim.lambda]
Submitter
Jason Merrill

Created on2009-09-04.00:00:00 last changed145 months ago

Messages

msg4379 (view)
Date: 2013-04-15.00:00:00

[Moved to DR status at the April, 2013 meeting as part of paper N3638.]

msg3749 (view)
Date: 2012-02-15.00:00:00

Additional note (February, 2012):

EWG requested that the adoption of this proposed resolution bepostponed to allow them to discuss it. The issue has thus beenreturned to "review" status pending EWG action.

msg3430 (view)
Date: 2011-08-15.00:00:00

Proposed resolution (August, 2011):

Change 7.5.6 [expr.prim.lambda] paragraph 4 as follows:

...If alambda-expression does not include atrailing-return-type, it is as if thetrailing-return-typedenotes the following type:

  • if the compound-statement is of the form

      {attribute-specifier-seqoptreturnexpression;

    the type of the returned expression after lvalue-to-rvalueconversion (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 noreturn statements in thecompound-statement, or allreturn statements returneither an expression of typevoid or noexpressionorbraced-init-list, the typevoid;

  • otherwise, if allreturn statements return anexpression and the types of the returned expressions afterlvalue-to-rvalue conversion (7.3.2 [conv.lval]),array-to-pointer conversion (7.3.3 [conv.array]), andfunction-to-pointer conversion (7.3.4 [conv.func]) arethe same, that common type;

  • otherwise, the program is ill-formed.

[Example:

  auto x1 = [](int i){ return i; }; // OK: return type isint  auto x2 = []{ return { 1, 2 }; }; // error: the return type isvoid (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 isint

end example]

msg2398 (view)
Date: 2010-08-23.00:00:00
N3092 comment US 30

There does not appear to be any technical difficulty that wouldrequire the current restriction that the return type of a lambda canbe deduced only if the body of the lambda consists of a single returnstatement. In particular, multiple return statements could bepermitted if they all return the same type.

History
DateUserActionArgs
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetmessages: +msg4379
2013-05-03 00:00:00adminsetstatus: review -> dr
2012-02-27 00:00:00adminsetmessages: +msg3749
2012-02-27 00:00:00adminsetstatus: ready -> review
2011-09-06 00:00:00adminsetmessages: +msg3430
2011-09-06 00:00:00adminsetstatus: open -> ready
2009-09-04 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp