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

Eric Fiselier via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 16 15:46:34 PDT 2022


EricWF accepted this revision.
EricWF added a comment.
Herald added a project: All.

We discussed making the test look something like:

  struct MovingDeleter {
    int value;
    static int delete_called;
    explicit MovingDeleter(int v) : value(v) {}
    MovingDeleter(MovingDeleter&& rhs) : value(rhs.value) { rhs.value = -1; }
    
    void operator()(int* p) const {
        assert(p);
        assert(value == 42);
        ++delete_called;
    }
    MovingDeleter& operator=(MovingDeleter&&) = delete;
    MovingDeleter(MovingDeleter const&) = delete;
    MovingDeleter& operator=(MovingDeleter const&) = delete;
    int *moves_;
  };
  
  int MovingDeleter::delete_called = 0;
  
  void test() {
      {
      std::unique_ptr<int, MovingDeleter> u(new int, MovingDeleter(42));
      std::shared_ptr<int> s(std::move(u));
      }
      assert(MovingDeleter::delete_called == 1);
  }

my only other concern was that we didn't throw between moving the deleter and releasing the unique_ptr. And we shouldn't. The allocator can't show on move, the deleter cannot throw on move, and `__enable_weak_this` is noexcept,  So this implementation should be safe and correct.


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