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.
Details
- Reviewers
mclow.lists EricWF - Group Reviewers
Restricted Project - Commits
- rG83564056d4b1: [libcxx] Add deduction guides for shared_ptr and weak_ptr
Diff Detail
- Repository
- rCXX libc++
Event Timeline
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 | ||
---|---|---|
24 | 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) 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. |
This looks good to me now.
You need to update www/cxx17_status.html appropriately as well.
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.
Thanks! Committed as
commit 83564056d4b186c9fcf016cdbb388755009f7b5a Author: Logan Smith <logan.r.smith0@gmail.com> Date: Thu May 7 12:07:01 2020 -0400 [libcxx] Add deduction guides for shared_ptr and weak_ptr 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. Differential Revision: https://reviews.llvm.org/D69603
This fails under the asan bot. @logan-5 Can you please take a look? http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-asan/builds/3235/steps/test.libcxx/logs/FAIL%3A%20libc%2B%2B%3A%3Adeduction.pass.cpp
Ack. It fails because there's a leak because a dummy deleter I used (D in deduction.pass.cpp) is a no-op. I suppose it should delete its argument as expected.
Should I submit another patch? Or does someone have the power to just commit the fix directly?
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp | ||
---|---|---|
27 | Here's the offending line. |
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:
Also, you should check the value of s. Make sure it points to the same thing as s0.