[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:
Volodymyr Sapsai
2018-12-19 20:08:43 +00:00
parent 1e048a3c69
commit d805c8746a
5 changed files with 193 additions and 22 deletions

View File

@@ -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();
}

View File

@@ -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();
}