[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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@349676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// template <class InputIter> vector(InputIter first, InputIter last);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
void test_ctor_under_alloc() {
|
||||
int arr1[] = {42};
|
||||
int arr2[] = {1, 101, 42};
|
||||
{
|
||||
typedef std::vector<int, cpp03_allocator<int> > C;
|
||||
typedef C::allocator_type Alloc;
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr1, arr1 + 1);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr2, arr2 + 3);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
}
|
||||
{
|
||||
typedef std::vector<int, cpp03_overload_allocator<int> > C;
|
||||
typedef C::allocator_type Alloc;
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr1, arr1 + 1);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr2, arr2 + 3);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_ctor_under_alloc();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// template <class InputIter> vector(InputIter first, InputIter last,
|
||||
// const allocator_type& a);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
void test_ctor_under_alloc() {
|
||||
int arr1[] = {42};
|
||||
int arr2[] = {1, 101, 42};
|
||||
{
|
||||
typedef std::vector<int, cpp03_allocator<int> > C;
|
||||
typedef C::allocator_type Alloc;
|
||||
Alloc a;
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr1, arr1 + 1, a);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr2, arr2 + 3, a);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
}
|
||||
{
|
||||
typedef std::vector<int, cpp03_overload_allocator<int> > C;
|
||||
typedef C::allocator_type Alloc;
|
||||
Alloc a;
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr1, arr1 + 1, a);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
{
|
||||
Alloc::construct_called = false;
|
||||
C v(arr2, arr2 + 3, a);
|
||||
assert(Alloc::construct_called);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_ctor_under_alloc();
|
||||
}
|
||||
Reference in New Issue
Block a user