Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
5 changed files
with
193 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
libcxx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
57 changes: 57 additions & 0 deletions
57
...xx/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters