This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


771. Move-construction of reference members of closure objects

Section: 7.5.5.2  [expr.prim.lambda.closure]     Status: CD2     Submitter: Jonathan Caves     Date: 9 February, 2009

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

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;
    public:
        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.

Proposed resolution (July, 2009)

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