summaryrefslogtreecommitdiffstats
path: root/libcxx/test/support/min_allocator.h
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2018-12-19 20:08:43 +0000
committerVolodymyr Sapsai <vsapsai@apple.com>2018-12-19 20:08:43 +0000
commite7652f5c0d099403b9f0ff5a93a39b809c20869d (patch)
tree33a9d8b604875bd1a067993b029231c655db7da4 /libcxx/test/support/min_allocator.h
parent660860e65977882b964839242528e3d6364d5f49 (diff)
downloadbcm5719-llvm-e7652f5c0d099403b9f0ff5a93a39b809c20869d.tar.gz
bcm5719-llvm-e7652f5c0d099403b9f0ff5a93a39b809c20869d.zip
[libcxx] Use custom allocator's `construct` in C++03 when available.
Makes libc++ behavior consistent between C++03 and C++11. Can use `decltype` in C++03 because `include/__config` defines a macro when `decltype` is not available. Reviewers: mclow.lists, EricWF, erik.pilkington, ldionne Reviewed By: ldionne Subscribers: dexonsmith, cfe-commits, howard.hinnant, ldionne, christof, jkorous, Quuxplusone Differential Revision: https://reviews.llvm.org/D48753 llvm-svn: 349676
Diffstat (limited to 'libcxx/test/support/min_allocator.h')
-rw-r--r--libcxx/test/support/min_allocator.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/libcxx/test/support/min_allocator.h b/libcxx/test/support/min_allocator.h
index a3af9e1db66..45474939744 100644
--- a/libcxx/test/support/min_allocator.h
+++ b/libcxx/test/support/min_allocator.h
@@ -14,6 +14,7 @@
#include <cstdlib>
#include <cstddef>
#include <cassert>
+#include <climits>
#include "test_macros.h"
@@ -131,6 +132,59 @@ public:
friend bool operator!=(malloc_allocator x, malloc_allocator y) {return !(x == y);}
};
+template <class T>
+struct cpp03_allocator : bare_allocator<T>
+{
+ typedef T value_type;
+ typedef value_type* pointer;
+
+ static bool construct_called;
+
+ // Returned value is not used but it's not prohibited.
+ pointer construct(pointer p, const value_type& val)
+ {
+ ::new(p) value_type(val);
+ construct_called = true;
+ return p;
+ }
+
+ std::size_t max_size() const
+ {
+ return UINT_MAX / sizeof(T);
+ }
+};
+template <class T> bool cpp03_allocator<T>::construct_called = false;
+
+template <class T>
+struct cpp03_overload_allocator : bare_allocator<T>
+{
+ typedef T value_type;
+ typedef value_type* pointer;
+
+ static bool construct_called;
+
+ void construct(pointer p, const value_type& val)
+ {
+ construct(p, val, std::is_class<T>());
+ }
+ void construct(pointer p, const value_type& val, std::true_type)
+ {
+ ::new(p) value_type(val);
+ construct_called = true;
+ }
+ void construct(pointer p, const value_type& val, std::false_type)
+ {
+ ::new(p) value_type(val);
+ construct_called = true;
+ }
+
+ std::size_t max_size() const
+ {
+ return UINT_MAX / sizeof(T);
+ }
+};
+template <class T> bool cpp03_overload_allocator<T>::construct_called = false;
+
#if TEST_STD_VER >= 11
OpenPOWER on IntegriCloud