[libcxx-commits] [PATCH] D81133: Use allocator_traits to consistently allocate/deallocate/construct/destroy objects in std::any

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 4 07:38:12 PDT 2020


mclow.lists added a comment.

> So I don't understand what the observable difference is here. Could you add a test?

An observable difference:

The user has specialized `std::allocator` for his type (and it is 'large' for `any`s purposes).
When he puts one into an `any`, his allocator specialization is called to allocate the memory.
When the `any` is destroyed (or he puts something else into the `any`), then the global `::free` is called.
This is potentially UB, since it passes `free` a pointer that didn't come from `new`.

There's a bunch of ways to do this. We should be consistent. 
This is one way to be consistent. Another would be to use `new`/`free` everywhere.
I'm not really sure which is best. Since we were using the allocator before, I made it so we used it everywhere.


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

https://reviews.llvm.org/D81133





More information about the libcxx-commits mailing list