Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.

983.unique_ptr reference deleters should not be moved from

Section: 20.3.1.3[unique.ptr.single]Status:ResolvedSubmitter: Howard HinnantOpened: 2009-02-10Last modified: 2016-01-28

Priority:Not Prioritized

View otheractive issues in [unique.ptr.single].

View all otherissues in [unique.ptr.single].

View all issues withResolved status.

Discussion:

Dave brought to my attention that when aunique_ptr has a non-const referencetype deleter, move constructing from it, even when theunique_ptr containingthe reference is an rvalue, could have surprising results:

D d(some-state);unique_ptr<A, D&> p(new A, d);unique_ptr<A, D> p2 = std::move(p);// has d's state changed here?

I agree with him. It is theunique_ptr that is the rvalue, not thedeleter. When the deleter is a reference type, theunique_ptr shouldrespect the "lvalueness" of the deleter.

Thanks Dave.

[Batavia (2009-05):]

Seems correct, but complicated enough that we recommend moving to Review.

[2009-10 Santa Cruz:]

Move to Ready.

[2010-03-14 Howard adds:]

We movedN3073to the formal motions page in Pittsburgh which should obsolete this issue. I'vemoved this issue to NAD Editorial, solved by N3073.

Rationale:

Solved byN3073.

Proposed resolution:

Change 20.3.1.3.2[unique.ptr.single.ctor], p20-21

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

-20-Requires: IfDE is not a reference type,construction of the deleterD from an rvalue of typeEshall be well formed and shall not throw an exception.OtherwiseE is a reference type and construction of the deleterD from an lvalue of typeE shall be well formed andshall not throw an exception.IfD isa reference type, thenE shall be the same type asD(diagnostic required).unique_ptr<U, E>::pointer shall beimplicitly convertible topointer. [Note: Theserequirements imply thatT andU are complete types.—end note]

-21-Effects: Constructs aunique_ptr which owns thepointer whichu owns (if any). If the deleterE is not a reference type,itthisdeleter is move constructed fromu's deleter, otherwisethe referencethis deleter is copy constructedfromu.'s deleter. After the construction,u no longerowns a pointer. [Note: The deleter constructor can be implementedwithstd::forward<DE>. —endnote]

Change 20.3.1.3.4[unique.ptr.single.asgn], p1-3

unique_ptr& operator=(unique_ptr&& u);

-1-Requires:If the deleterD is not a reference type,Aassignment of the deleterD from an rvalueD shall not throw an exception.Otherwise the deleterD is a reference type,and assignment of the deleterD from an lvalueD shall not throw an exception.

-2-Effects: reset(u.release()) followed byanmove assignment fromu's deleter to this deleterstd::forward<D>(u.get_deleter()).

-3-Postconditions: Thisunique_ptr now owns the pointerwhichu owned, andu no longer owns it.[Note: IfD is a reference type, then the referenced lvalue deleters aremove assigned. —end note]

Change 20.3.1.3.4[unique.ptr.single.asgn], p6-7

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

Requires:If the deleterE is not a reference type,Aassignment of the deleterD from an rvalueDE shall not throw an exception.Otherwise the deleterE is a reference type,and assignment of the deleterD from an lvalueE shall not throw an exception.unique_ptr<U, E>::pointer shall be implicitly convertible topointer.[Note: These requirements imply thatT andU>are complete types. —end note]

Effects:reset(u.release()) followed byanmove assignment fromu's deleter to this deleterstd::forward<E>(u.get_deleter()).If eitherD orE is a reference type, then the referenced lvaluedeleter participates in the move assignment.


[8]ページ先頭

©2009-2026 Movatter.jp