[PATCH] D25154: [libc++] Fix stack_allocator
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 1 00:06:50 PDT 2016
EricWF created this revision.
EricWF added reviewers: mclow.lists, howard.hinnant, STL_MSFT.
EricWF added a subscriber: cfe-commits.
To quote STL the problems with stack allocator are"
> "stack_allocator<T, N> is seriously nonconformant to N4582 17.6.3.5 [allocator.requirements].
> First, it lacks a rebinding constructor. (The nested "struct rebind" isn't sufficient.)
> Second, it lacks templated equality/inequality.
> Third, it completely ignores alignment.
> Finally, and most severely, the Standard forbids its existence. Allocators are forbidden from returning memory "inside themselves". This requirement is implied by the Standard's requirements for rebinding and equality. It's permitted to return memory from a separate buffer object on the stack, though."
This patch attempts to address all of those issues.
First, instead of storing the buffer inside the allocator I've change `stack_allocator` to accept the buffer as an argument.
Second, in order to fix rebinding I changed the parameter list from `<class T, size_t NumElements>` to `<class T, size_t NumBytes>`. This allows allocator rebinding
between types that have different sizes.
Third, I added copy and rebinding constructors and assignment operators.
And finally I fixed the allocation logic to always return properly aligned storage.
https://reviews.llvm.org/D25154
Files:
test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp
test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp
test/std/containers/container.adaptors/queue/queue.cons/ctor_default.pass.cpp
test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp
test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp
test/std/containers/sequences/deque/deque.cons/default.pass.cpp
test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
test/std/containers/sequences/deque/deque.cons/size.pass.cpp
test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp
test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp
test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp
test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp
test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
test/std/containers/sequences/list/list.cons/size_type.pass.cpp
test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp
test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp
test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp
test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp
test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp
test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp
test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp
test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp
test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp
test/std/containers/stack_allocator.h
test/support/stack_allocator.h
test/support/test.support/test_stack_allocator.pass.cpp
test/support/test_macros.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25154.73188.patch
Type: text/x-patch
Size: 50870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161001/bee5f381/attachment-0001.bin>
More information about the cfe-commits
mailing list