Title
auto deduction and lambda return type deduction.
Status
cd3
Section
7.5.5 [expr.prim.lambda]
Submitter
Jason Merrill

Created on 2010-03-09.00:00:00 last changed 114 months ago

Messages

Date: 2013-04-15.00:00:00

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

Date: 2014-11-15.00:00:00

Notes from the November, 2014 meeting:

CWG agreed that the change embodied in paper N3638 should be considered to have been a DR against C++11.

Date: 2014-11-24.00:00:00

Proposed resolution, November, 2014:

This issue was actually resolved by paper N3638, adopted at the April, 2013 meeting. It is returned to "review" status to allow consideration of whether the resolution should be considered a change for C++14 or a retroactive change to C++11.

Date: 2014-03-03.00:00:00

Additional note, February, 2014:

EWG noted that g++ and clang differ in their treatment of this example and referred it back to CWG for resolution.

Date: 2010-03-09.00:00:00

auto and lambda return types use slightly different rules for determining the result type from an expression. auto uses the rules in 13.10.3.2 [temp.deduct.call], which explicitly drops top-level cv-qualification in all cases, while the lambda return type is based on the lvalue-to-rvalue conversion, which drops cv-qualification only for non-class types. As a result:

    struct A { };

    const A f();

    auto a = f();               // decltype(a) is A
    auto b = []{ return f(); }; // decltype(b()) is const A

This seems like an unnecessary inconsistency.

John Spicer:

The difference is intentional; auto is intended only to give a const type if you explicitly ask for it, while the lambda return type should generally be the type of the expression.

Daniel Krügler:

Another inconsistency: with auto, use of a braced-init-list can deduce a specialization of std::initializer_list; it would be helpful if the same could be done for a lambda return type.

History
Date User Action Args
2014-11-24 00:00:00adminsetmessages: + msg5264
2014-11-24 00:00:00adminsetmessages: + msg5263
2014-11-24 00:00:00adminsetstatus: nad -> cd3
2014-07-07 00:00:00adminsetmessages: + msg5111
2014-07-07 00:00:00adminsetstatus: open -> nad
2014-03-03 00:00:00adminsetmessages: + msg4904
2014-03-03 00:00:00adminsetstatus: extension -> open
2010-08-23 00:00:00adminsetstatus: open -> extension
2010-03-09 00:00:00admincreate