Move-construction of reference members of closure objects
7.5.5 [expr.prim.lambda]
Jonathan Caves

Created on 2009-02-09.00:00:00 last changed 144 months ago


Date: 2009-07-15.00:00:00

[Voted into the WP at the July, 2009 meeting as part of N2927.]

Date: 2009-07-15.00:00:00

Proposed resolution (July, 2009)

See document PL22.16/09-0117 = WG21 N2927.

Date: 2009-02-09.00:00:00

According to 7.5.5 [expr.prim.lambda] paragraph 11, the closure class “has a public move constructor that performs a member-wise move.” Although the terms “move constructor” and “member-wise move” are not currently defined (see issue 680), this presumably means that a lambda like [&i]{} results in a closure class similar to:

    class F {
        int& i;
        F(&& other):
            i(std::move(other.i)) { }
        // etc.

This constructor is ill-formed because it attempts to initialize an lvalue reference to non-const int with the rvalue returned by std::move.

It is not clear whether this should be handled by:

  1. Not generating the move constructor.

  2. Generating the declaration of the move constructor but only defining it (and giving the corresponding error) if the move constructor would be used, similar to the handling of other implicitly-defined special member functions.

  3. Generating the move constructor but copy-constructing any reference members.
Date User Action Args
2010-03-29 00:00:00adminsetstatus: wp -> cd2
2009-11-08 00:00:00adminsetstatus: dr -> wp
2009-08-03 00:00:00adminsetmessages: + msg2246
2009-08-03 00:00:00adminsetstatus: review -> dr
2009-03-23 00:00:00adminsetmessages: + msg1914
2009-02-09 00:00:00admincreate