[PATCH] D22973: [libcxx] [test] Add TEST_STACK_ALLOCATOR_WORKAROUND.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 13:04:02 PDT 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Add TEST_STACK_ALLOCATOR_WORKAROUND. As I reported to Eric and Marshall:

"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."

I would like to be able to run libcxx's tests without any local patches (I can inject macros etc. via a force-included header in a separate directory). I'm down to one local patch dealing with stack_allocator. Adding this workaround macro will allow me to consume libcxx's tests unchanged.

https://reviews.llvm.org/D22973

Files:
  test/std/containers/stack_allocator.h

Index: test/std/containers/stack_allocator.h
===================================================================
--- test/std/containers/stack_allocator.h
+++ test/std/containers/stack_allocator.h
@@ -13,6 +13,18 @@
 #include <cstddef>
 #include <new>
 
+#ifdef TEST_STACK_ALLOCATOR_WORKAROUND
+
+#include <memory>
+
+template <class T, std::size_t N>
+using stack_allocator = std::allocator<T>;
+
+// This is a temporary workaround for library implementations
+// that can't tolerate the nonconformant stack_allocator below.
+
+#else  // TEST_STACK_ALLOCATOR_WORKAROUND
+
 template <class T, std::size_t N>
 class stack_allocator
 {
@@ -63,4 +75,6 @@
 void
 swap(stack_allocator<T, N>& x, stack_allocator<T, N>& y) {}
 
+#endif  // TEST_STACK_ALLOCATOR_WORKAROUND
+
 #endif  // STACK_ALLOCATOR_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22973.66164.patch
Type: text/x-patch
Size: 797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160729/6770db4d/attachment.bin>


More information about the cfe-commits mailing list