[libcxx-commits] [PATCH] D119159: [libc++] Make shared_ptr move unique_ptr's deleter

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 9 12:00:24 PST 2022


Quuxplusone added inline comments.


================
Comment at: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp:235
+    { // LWG 3548
+#if TEST_STD_VER > 3
+      {
----------------
Although I'm not convinced we need anything special for C++03 here, actually. Clang //does// support rvalue references in its non-pedantic C++03 mode, which is all we support; so I'd be surprised if anything behaved differently in C++03 mode.  This seems to be an at-least-moderately-deep rabbit hole; see e.g. https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/shared_ptr.h#L477-L481 (additional copy instead of move) and https://github.com/llvm/llvm-project/blob/main/libcxx/include/__memory/shared_ptr.h#L237 (additional move instead of nothing). @ashermancinelli, would you //like// to explore this rabbit hole? If not, I'll do it.

Re styling `TEST_STD_VER` checks: `git grep` is your friend.
```
git grep -h 'TEST_STD_VER >' ../libcxx | sort | uniq -c | sort -n
```


================
Comment at: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp:250-258
+        int moves = 0;
+        int *p = new int[8];
+        std::unique_ptr<int[], MovingDeleter> u(p, MovingDeleter(&moves));
+        assert(moves == 1);
+        std::shared_ptr<int[]> s(std::move(u));
+        assert(moves >= 2);
+        assert(u == nullptr);
----------------
The point of using a MovingDeleter is that you don't have to mess with raw `new` and `delete`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119159/new/

https://reviews.llvm.org/D119159



More information about the libcxx-commits mailing list