1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // template <class... Args> reference emplace_back(Args&&... args);
14 // return type is 'reference' in C++17; 'void' before
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 #include "test_allocator.h"
22 #include "asan_testing.h"
30 A
& operator=(const A
&);
52 int geti() const {return i_
;}
53 double getd() const {return d_
;}
61 A
& r1
= c
.emplace_back(2, 3.5);
62 assert(c
.size() == 1);
63 assert(&r1
== &c
.back());
64 assert(c
.front().geti() == 2);
65 assert(c
.front().getd() == 3.5);
66 assert(is_contiguous_container_asan_correct(c
));
67 A
& r2
= c
.emplace_back(3, 4.5);
68 assert(c
.size() == 2);
69 assert(&r2
== &c
.back());
71 c
.emplace_back(2, 3.5);
72 assert(c
.size() == 1);
73 assert(c
.front().geti() == 2);
74 assert(c
.front().getd() == 3.5);
75 assert(is_contiguous_container_asan_correct(c
));
76 c
.emplace_back(3, 4.5);
77 assert(c
.size() == 2);
79 assert(c
.front().geti() == 2);
80 assert(c
.front().getd() == 3.5);
81 assert(c
.back().geti() == 3);
82 assert(c
.back().getd() == 4.5);
83 assert(is_contiguous_container_asan_correct(c
));
86 std::vector
<A
, limited_allocator
<A
, 4> > c
;
88 A
& r1
= c
.emplace_back(2, 3.5);
89 assert(c
.size() == 1);
90 assert(&r1
== &c
.back());
91 assert(c
.front().geti() == 2);
92 assert(c
.front().getd() == 3.5);
93 assert(is_contiguous_container_asan_correct(c
));
94 A
& r2
= c
.emplace_back(3, 4.5);
95 assert(c
.size() == 2);
96 assert(&r2
== &c
.back());
98 c
.emplace_back(2, 3.5);
99 assert(c
.size() == 1);
100 assert(c
.front().geti() == 2);
101 assert(c
.front().getd() == 3.5);
102 assert(is_contiguous_container_asan_correct(c
));
103 c
.emplace_back(3, 4.5);
104 assert(c
.size() == 2);
106 assert(c
.front().geti() == 2);
107 assert(c
.front().getd() == 3.5);
108 assert(c
.back().geti() == 3);
109 assert(c
.back().getd() == 4.5);
110 assert(is_contiguous_container_asan_correct(c
));
113 std::vector
<A
, min_allocator
<A
>> c
;
114 #if TEST_STD_VER > 14
115 A
& r1
= c
.emplace_back(2, 3.5);
116 assert(c
.size() == 1);
117 assert(&r1
== &c
.back());
118 assert(c
.front().geti() == 2);
119 assert(c
.front().getd() == 3.5);
120 assert(is_contiguous_container_asan_correct(c
));
121 A
& r2
= c
.emplace_back(3, 4.5);
122 assert(c
.size() == 2);
123 assert(&r2
== &c
.back());
125 c
.emplace_back(2, 3.5);
126 assert(c
.size() == 1);
127 assert(c
.front().geti() == 2);
128 assert(c
.front().getd() == 3.5);
129 assert(is_contiguous_container_asan_correct(c
));
130 c
.emplace_back(3, 4.5);
131 assert(c
.size() == 2);
133 assert(c
.front().geti() == 2);
134 assert(c
.front().getd() == 3.5);
135 assert(c
.back().geti() == 3);
136 assert(c
.back().getd() == 4.5);
137 assert(is_contiguous_container_asan_correct(c
));
140 std::vector
<Tag_X
, TaggingAllocator
<Tag_X
>> c
;
142 assert(c
.size() == 1);
143 c
.emplace_back(1, 2, 3);
144 assert(c
.size() == 2);
145 assert(is_contiguous_container_asan_correct(c
));
149 int arr
[] = {0, 1, 2, 3, 4};
151 std::vector
<int> c(arr
, arr
+sz
);
152 while (c
.size() < c
.capacity())
154 c
.emplace_back(c
.front());
155 assert(c
.back() == 0);
156 for (int i
= 0; i
< sz
; ++i
)