This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.

2047. Incorrect "mixed" move-assignment semantics of unique_ptr

Section: 20.3.1.3.4 [unique.ptr.single.asgn] Status: C++14 Submitter: Daniel Krügler Opened: 2011-04-16 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [unique.ptr.single.asgn].

View all issues with C++14 status.

Discussion:

The semantics described in 20.3.1.3.4 [unique.ptr.single.asgn] p. 6

Effects: Transfers ownership from u to *this as if […] followed by an assignment from std::forward<D>(u.get_deleter()).

contradicts to the pre-conditions described in p. 4:

Requires: If E is not a reference type, assignment of the deleter from an rvalue of type E shall be well-formed and shall not throw an exception. Otherwise, E is a reference type and assignment of the deleter from an lvalue of type E shall be well-formed and shall not throw an exception.

Either the pre-conditions are incorrect or the semantics should be an assignment from std::forward<E>(u.get_deleter()), instead.

It turns out that this contradiction is due to an incorrect transcription from the proposed resolution of 983 to the finally accepted proposal n3073 (see bullet 12) as confirmed by Howard Hinnant, thus the type argument provided to std::forward must be fixed as indicated.

[Bloomington, 2011]

Move to Ready

Proposed resolution:

This wording is relative to the FDIS.

  1. Edit 20.3.1.3.4 [unique.ptr.single.asgn] p. 6 as indicated:

    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
    

    4 - Requires: If E is not a reference type, assignment of the deleter from an rvalue of type E shall be well-formed and shall not throw an exception. Otherwise, E is a reference type and assignment of the deleter from an lvalue of type E shall be well-formed and shall not throw an exception.

    5 - Remarks: This operator shall not participate in overload resolution unless:

    • unique_ptr<U, E>::pointer is implicitly convertible to pointer and
    • U is not an array type.

    6 - Effects: Transfers ownership from u to *this as if by calling reset(u.release()) followed by an assignment from std::forward<DE>(u.get_deleter()).

    7 - Returns: *this.