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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to