Page MenuHomePhabricator

[libcxx] Add deduction guides for shared_ptr and weak_ptr
AcceptedPublic

Authored by logan-5 on Oct 29 2019, 9:58 PM.

Details

Summary

This patch adds deduction guides to <memory> to allow deducing construction of shared_ptrs from unique_ptrs, and from weak_ptrs and vice versa, as specified by C++17.

Diff Detail

Repository
rCXX libc++

Event Timeline

logan-5 created this revision.Oct 29 2019, 9:58 PM
logan-5 updated this revision to Diff 227139.Oct 30 2019, 10:31 AM

Add a newline to synopsis

The tests should be more comprehensive; they should ASSERT_SAME_TYPE(decltype(s), XXX) to make sure that the deduction guides actually return the correct type, rather than just compile.

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
25

When you're testing type-deduction, I find it much easier to convince myself that the types are correct if you are explicit whenever possible (instead of just auto everywhere)
Example:

using SP = std::shared_ptr<A>;
using WP = std::weak_ptr<A>;

SP s0 = new A;
WP w = s0;
auto s = std::shared_ptr(w);
ASSERT_SAME_TYPE(decltype(s), SP);

Also, you should check the value of s. Make sure it points to the same thing as s0.

mclow.lists requested changes to this revision.Oct 31 2019, 11:34 PM
This revision now requires changes to proceed.Oct 31 2019, 11:34 PM
logan-5 updated this revision to Diff 227493.Nov 1 2019, 11:39 AM

Beefed up the tests in response to some feedback -- thanks.

logan-5 marked an inline comment as done.Nov 18 2019, 11:12 AM

ping

Hello! Pinging this again.

mclow.lists accepted this revision.Sun, Dec 29, 8:44 PM

This looks good to me now.
You need to update www/cxx17_status.html appropriately as well.

This revision is now accepted and ready to land.Sun, Dec 29, 8:44 PM

Thanks Marshall. As for www/cxx1z_status.html, my best guess is that it doesn't need updating, since the row for P0433R2 lists it as In progress, which I believe is still the case after this patch. Please correct me if I'm wrong. Otherwise, I'd be grateful if someone with commit access could help me tie a bow around this.