[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

Billy Robert O'Neal III via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 26 16:04:25 PDT 2018


BillyONeal added subscribers: STL_MSFT, BillyONeal.
BillyONeal added a comment.

@mclow.lists
@STL_MSFT

Why did tests for this this go into std? [reentrancy]/1 says this isn't required to work. Moreover, assignments in the dtor like this *can't* work in the general case because they would try to overwrite the SSO space. e.g. what do you expect this to do?

  std::function<void()> global;
  
  struct B {
      int data = 1729;
      void operator() {}
  };
  
  struct A {
      int data = 42;
      ~A() {
          global = std::function<void()>(B{}); // whoops, constructs a B on top of A if Small Functor Optimization engages
          assert(data == 42);
      }
  
      void operator() {}
  };
  
  int main() {
      global = std::function<void ()>(A{});
      global = nullptr;
  }




Repository:
  rCXX libc++

https://reviews.llvm.org/D34331





More information about the cfe-commits mailing list