Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// reference operator[](size_type n);
#include <vector>
#include <cassert>
#include <cstdlib>
#include "min_allocator.h"
#include "asan_testing.h"
#ifndef _LIBCPP_HAS_NO_ASAN
extern "C" void __asan_set_error_exit_code(int);
int main()
{
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
c.reserve(2*c.size());
T foo = c[c.size()]; // bad, but not caught by ASAN
}
#endif
__asan_set_error_exit_code(0);
{
typedef int T;
typedef std::vector<T> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
c.reserve(2*c.size());
assert(is_contiguous_container_asan_correct(c));
assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity()));
T foo = c[c.size()]; // should trigger ASAN
assert(false); // if we got here, ASAN didn't trigger
}
}
#else
int main () { return 0; }
#endif

View File

@@ -0,0 +1,198 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// Test asan vector annotations with a class that throws in a CTOR.
#include <vector>
#include <cassert>
#include "asan_testing.h"
class X {
public:
X(const X &x) { Init(x.a); }
X(char arg) { Init(arg); }
X() { Init(42); }
X &operator=(const X &x) {
Init(x.a);
return *this;
}
void Init(char arg) {
if (arg == 42)
throw 0;
if (arg == 66)
arg = 42;
a = arg;
}
char get() const { return a; }
void set(char arg) { a = arg; }
private:
char a;
};
void test_push_back() {
std::vector<X> v;
v.reserve(2);
v.push_back(X(2));
assert(v.size() == 1);
try {
v.push_back(X(66));
assert(0);
} catch (int e) {
assert(v.size() == 1);
}
assert(v.size() == 1);
assert(is_contiguous_container_asan_correct(v));
}
void test_emplace_back() {
#ifndef _LIBCPP_HAS_NO_VARIADICS
std::vector<X> v;
v.reserve(2);
v.push_back(X(2));
assert(v.size() == 1);
try {
v.emplace_back(42);
assert(0);
} catch (int e) {
assert(v.size() == 1);
}
assert(v.size() == 1);
assert(is_contiguous_container_asan_correct(v));
#endif // _LIBCPP_HAS_NO_VARIADICS
}
void test_insert_range() {
std::vector<X> v;
v.reserve(4);
v.push_back(X(1));
v.push_back(X(2));
assert(v.size() == 2);
assert(v.capacity() >= 4);
try {
char a[2] = {21, 42};
v.insert(v.end(), a, a + 2);
assert(0);
} catch (int e) {
assert(v.size() == 3);
}
assert(v.size() == 3);
assert(is_contiguous_container_asan_correct(v));
}
void test_insert() {
std::vector<X> v;
v.reserve(3);
v.insert(v.end(), X(1));
v.insert(v.begin(), X(2));
assert(v.size() == 2);
try {
v.insert(v.end(), X(66));
assert(0);
} catch (int e) {
assert(v.size() == 2);
}
assert(v.size() == 2);
assert(is_contiguous_container_asan_correct(v));
}
void test_emplace() {
#ifndef _LIBCPP_HAS_NO_VARIADICS
std::vector<X> v;
v.reserve(3);
v.insert(v.end(), X(1));
v.insert(v.begin(), X(2));
assert(v.size() == 2);
try {
v.emplace(v.end(), 42);
assert(0);
} catch (int e) {
assert(v.size() == 2);
}
assert(v.size() == 2);
assert(is_contiguous_container_asan_correct(v));
#endif // _LIBCPP_HAS_NO_VARIADICS
}
void test_insert_range2() {
std::vector<X> v;
v.reserve(4);
v.insert(v.end(), X(1));
v.insert(v.begin(), X(2));
assert(v.size() == 2);
assert(v.capacity() >= 4);
try {
char a[2] = {10, 42};
v.insert(v.begin(), a, a + 2);
assert(0);
} catch (int e) {
assert(v.size() <= 4);
assert(is_contiguous_container_asan_correct(v));
return;
}
assert(0);
}
void test_insert_n() {
std::vector<X> v;
v.reserve(10);
v.insert(v.end(), X(1));
v.insert(v.begin(), X(2));
assert(v.size() == 2);
try {
v.insert(v.begin(), 1, X(66));
assert(0);
} catch (int e) {
assert(v.size() <= 3);
assert(is_contiguous_container_asan_correct(v));
return;
}
assert(0);
}
void test_resize() {
std::vector<X> v;
v.reserve(3);
v.push_back(X(0));
try {
v.resize(3);
assert(0);
} catch (int e) {
assert(v.size() == 1);
}
assert(v.size() == 1);
assert(is_contiguous_container_asan_correct(v));
}
void test_resize_param() {
std::vector<X> v;
v.reserve(3);
v.push_back(X(0));
try {
v.resize(3, X(66));
assert(0);
} catch (int e) {
assert(v.size() == 1);
}
assert(v.size() == 1);
assert(is_contiguous_container_asan_correct(v));
}
int main() {
test_push_back();
test_emplace_back();
test_insert_range();
test_insert();
test_emplace();
test_insert_range2();
test_insert_n();
test_resize();
test_resize_param();
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector<const int> v; // an extension
#include <vector>
#include <type_traits>
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
std::vector<const int> v = {1, 2, 3};
#endif
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call back() on empty container.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
assert(c.back() == 0);
c.clear();
assert(c.back() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
assert(c.back() == 0);
c.clear();
assert(c.back() == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call back() on empty const container.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
const C c;
assert(c.back() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const C c;
assert(c.back() == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call front() on empty const container.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
const C c;
assert(c.front() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const C c;
assert(c.front() == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

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>
// Index const vector out of bounds.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
const C c(1);
assert(c[0] == 0);
assert(c[1] == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const C c(1);
assert(c[0] == 0);
assert(c[1] == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call front() on empty container.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
assert(c.front() == 0);
c.clear();
assert(c.front() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
assert(c.front() == 0);
c.clear();
assert(c.front() == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Index vector out of bounds.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
assert(c[0] == 0);
c.clear();
assert(c[0] == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
assert(c[0] == 0);
c.clear();
assert(c[0] == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

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>
// Compare iterators from different containers with <.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c1;
C c2;
bool b = c1.begin() < c2.begin();
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c1;
C c2;
bool b = c1.begin() < c2.begin();
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

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>
// Subtract iterators from different containers.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c1;
C c2;
int i = c1.begin() - c2.begin();
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c1;
C c2;
int i = c1.begin() - c2.begin();
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Index iterator out of bounds.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
C::iterator i = c.begin();
assert(i[0] == 0);
assert(i[1] == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.begin();
assert(i[0] == 0);
assert(i[1] == 0);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Add to iterator out of bounds.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
C::iterator i = c.begin();
i += 1;
assert(i == c.end());
i = c.begin();
i += 2;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.begin();
i += 1;
assert(i == c.end());
i = c.begin();
i += 2;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Decrement iterator prior to begin.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
C::iterator i = c.end();
--i;
assert(i == c.begin());
--i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.end();
--i;
assert(i == c.begin());
--i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Increment iterator past end.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

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>
// Dereference non-dereferenceable iterator.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c(1);
C::iterator i = c.end();
T j = *i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.end();
T j = *i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,165 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator begin();
// iterator end();
// const_iterator begin() const;
// const_iterator end() const;
// const_iterator cbegin() const;
// const_iterator cend() const;
#include <vector>
#include <cassert>
#include <iterator>
#include "min_allocator.h"
struct A
{
int first;
int second;
};
int main()
{
{
typedef int T;
typedef std::vector<T> C;
C c;
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::vector<T> C;
const C c;
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::vector<T> C;
C c;
C::const_iterator i = c.cbegin();
C::const_iterator j = c.cend();
assert(std::distance(i, j) == 0);
assert(i == j);
assert(i == c.end());
}
{
typedef int T;
typedef std::vector<T> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
C::iterator i = c.begin();
assert(*i == 0);
++i;
assert(*i == 1);
*i = 10;
assert(*i == 10);
assert(std::distance(c.begin(), c.end()) == 10);
}
{
typedef int T;
typedef std::vector<T> C;
C::iterator i;
C::const_iterator j;
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c;
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const C c;
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C c;
C::const_iterator i = c.cbegin();
C::const_iterator j = c.cend();
assert(std::distance(i, j) == 0);
assert(i == j);
assert(i == c.end());
}
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
C::iterator i = c.begin();
assert(*i == 0);
++i;
assert(*i == 1);
*i = 10;
assert(*i == 10);
assert(std::distance(c.begin(), c.end()) == 10);
}
{
typedef int T;
typedef std::vector<T, min_allocator<T>> C;
C::iterator i;
C::const_iterator j;
}
{
typedef A T;
typedef std::vector<T, min_allocator<T>> C;
C c = {A{1, 2}};
C::iterator i = c.begin();
i->first = 3;
C::const_iterator j = i;
assert(j->first == 3);
}
#endif
#if _LIBCPP_STD_VER > 11
{ // N3644 testing
typedef std::vector<int> C;
C::iterator ii1{}, ii2{};
C::iterator ii4 = ii1;
C::const_iterator cii{};
assert ( ii1 == ii2 );
assert ( ii1 == ii4 );
assert (!(ii1 != ii2 ));
assert ( (ii1 == cii ));
assert ( (cii == ii1 ));
assert (!(ii1 != cii ));
assert (!(cii != ii1 ));
assert (!(ii1 < cii ));
assert (!(cii < ii1 ));
assert ( (ii1 <= cii ));
assert ( (cii <= ii1 ));
assert (!(ii1 > cii ));
assert (!(cii > ii1 ));
assert ( (ii1 >= cii ));
assert ( (cii >= ii1 ));
assert (cii - ii1 == 0);
assert (ii1 - cii == 0);
}
#endif
}

View File

@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Test nested types and default template args:
// template <class T, class Allocator = allocator<T> >
// class vector
// {
// public:
// typedef T value_type;
// typedef Allocator allocator_type;
// typedef typename allocator_type::reference reference;
// typedef typename allocator_type::const_reference const_reference;
// typedef implementation-defined iterator;
// typedef implementation-defined const_iterator;
// typedef typename allocator_type::size_type size_type;
// typedef typename allocator_type::difference_type difference_type;
// typedef typename allocator_type::pointer pointer;
// typedef typename allocator_type::const_pointer const_pointer;
// typedef std::reverse_iterator<iterator> reverse_iterator;
// typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
// };
#include <vector>
#include <iterator>
#include <type_traits>
#include "test_allocator.h"
#include "../../Copyable.h"
#include "min_allocator.h"
template <class T, class Allocator>
void
test()
{
typedef std::vector<T, Allocator> C;
static_assert((std::is_same<typename C::value_type, T>::value), "");
static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), "");
static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), "");
static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), "");
static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), "");
static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), "");
static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), "");
static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), "");
static_assert((std::is_same<
typename std::iterator_traits<typename C::iterator>::iterator_category,
std::random_access_iterator_tag>::value), "");
static_assert((std::is_same<
typename std::iterator_traits<typename C::const_iterator>::iterator_category,
std::random_access_iterator_tag>::value), "");
static_assert((std::is_same<
typename C::reverse_iterator,
std::reverse_iterator<typename C::iterator> >::value), "");
static_assert((std::is_same<
typename C::const_reverse_iterator,
std::reverse_iterator<typename C::const_iterator> >::value), "");
}
int main()
{
test<int, test_allocator<int> >();
test<int*, std::allocator<int*> >();
test<Copyable, test_allocator<Copyable> >();
static_assert((std::is_same<std::vector<char>::allocator_type,
std::allocator<char> >::value), "");
#if __cplusplus >= 201103L
static_assert((std::is_same<std::vector<int, min_allocator<int>>::value_type, int>::value), "");
static_assert((std::is_same<std::vector<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), "");
static_assert((std::is_same<std::vector<int, min_allocator<int>>::reference, int&>::value), "");
static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_reference, const int&>::value), "");
static_assert((std::is_same<std::vector<int, min_allocator<int>>::pointer, min_pointer<int>>::value), "");
static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), "");
#endif
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// 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>
// size_type capacity() const;
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v;
assert(v.capacity() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int> v(100);
assert(v.capacity() == 100);
v.push_back(0);
assert(v.capacity() > 101);
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v;
assert(v.capacity() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, min_allocator<int>> v(100);
assert(v.capacity() == 100);
v.push_back(0);
assert(v.capacity() > 101);
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void reserve(size_type n);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v;
v.reserve(10);
assert(v.capacity() >= 10);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int> v(100);
assert(v.capacity() == 100);
v.reserve(50);
assert(v.size() == 100);
assert(v.capacity() == 100);
v.reserve(150);
assert(v.size() == 100);
assert(v.capacity() == 150);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, stack_allocator<int, 250> > v(100);
assert(v.capacity() == 100);
v.reserve(50);
assert(v.size() == 100);
assert(v.capacity() == 100);
v.reserve(150);
assert(v.size() == 100);
assert(v.capacity() == 150);
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v;
v.reserve(10);
assert(v.capacity() >= 10);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, min_allocator<int>> v(100);
assert(v.capacity() == 100);
v.reserve(50);
assert(v.size() == 100);
assert(v.capacity() == 100);
v.reserve(150);
assert(v.size() == 100);
assert(v.capacity() == 150);
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void resize(size_type sz);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "../../../MoveOnly.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly> v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<int> v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, stack_allocator<int, 300> > v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void resize(size_type sz, const value_type& x);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v(100);
v.resize(50, 1);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(v == std::vector<int>(50));
v.resize(200, 1);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
for (unsigned i = 0; i < 50; ++i)
assert(v[i] == 0);
for (unsigned i = 50; i < 200; ++i)
assert(v[i] == 1);
}
{
std::vector<int, stack_allocator<int, 300> > v(100);
v.resize(50, 1);
assert(v.size() == 50);
assert(v.capacity() == 100);
v.resize(200, 1);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v(100);
v.resize(50, 1);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
assert((v == std::vector<int, min_allocator<int>>(50)));
v.resize(200, 1);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
for (unsigned i = 0; i < 50; ++i)
assert(v[i] == 0);
for (unsigned i = 50; i < 200; ++i)
assert(v[i] == 1);
}
{
std::vector<int, min_allocator<int>> v(100);
v.resize(50, 1);
assert(v.size() == 50);
assert(v.capacity() == 100);
assert(is_contiguous_container_asan_correct(v));
v.resize(200, 1);
assert(v.size() == 200);
assert(v.capacity() >= 200);
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void shrink_to_fit();
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v(100);
v.push_back(1);
assert(is_contiguous_container_asan_correct(v));
v.shrink_to_fit();
assert(v.capacity() == 101);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, stack_allocator<int, 401> > v(100);
v.push_back(1);
assert(is_contiguous_container_asan_correct(v));
v.shrink_to_fit();
assert(v.capacity() == 101);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
}
#ifndef _LIBCPP_NO_EXCEPTIONS
{
std::vector<int, stack_allocator<int, 400> > v(100);
v.push_back(1);
assert(is_contiguous_container_asan_correct(v));
v.shrink_to_fit();
assert(v.capacity() == 200);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
}
#endif
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v(100);
v.push_back(1);
assert(is_contiguous_container_asan_correct(v));
v.shrink_to_fit();
assert(v.capacity() == 101);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void swap(vector& x);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v1(100);
std::vector<int> v2(200);
assert(is_contiguous_container_asan_correct(v1));
assert(is_contiguous_container_asan_correct(v2));
v1.swap(v2);
assert(v1.size() == 200);
assert(v1.capacity() == 200);
assert(is_contiguous_container_asan_correct(v1));
assert(v2.size() == 100);
assert(v2.capacity() == 100);
assert(is_contiguous_container_asan_correct(v2));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v1(100);
std::vector<int, min_allocator<int>> v2(200);
assert(is_contiguous_container_asan_correct(v1));
assert(is_contiguous_container_asan_correct(v2));
v1.swap(v2);
assert(v1.size() == 200);
assert(v1.capacity() == 200);
assert(is_contiguous_container_asan_correct(v1));
assert(v2.size() == 100);
assert(v2.capacity() == 100);
assert(is_contiguous_container_asan_correct(v2));
}
#endif
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector& operator=(const vector& c);
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
int main()
{
{
std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5));
std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3));
l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == test_allocator<int>(3));
}
{
std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5));
std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<int>(5));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>());
std::vector<int, min_allocator<int> > l2(l, min_allocator<int>());
l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<int>());
}
#endif
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void assign(initializer_list<value_type> il);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int> d;
d.assign({3, 4, 5, 6});
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> d;
d.assign({3, 4, 5, 6});
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector& operator=(vector&& c);
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
{
std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
l2 = std::move(l);
assert(l2 == lo);
assert(!l.empty());
assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
assert(is_contiguous_container_asan_correct(l2));
}
{
std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(const Alloc& = Alloc());
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "../../../NotConstructible.h"
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C>
void
test0()
{
C c;
assert(c.__invariants());
assert(c.empty());
assert(c.get_allocator() == typename C::allocator_type());
assert(is_contiguous_container_asan_correct(c));
#if __cplusplus >= 201103L
C c1 = {};
assert(c1.__invariants());
assert(c1.empty());
assert(c1.get_allocator() == typename C::allocator_type());
assert(is_contiguous_container_asan_correct(c1));
#endif
}
template <class C>
void
test1(const typename C::allocator_type& a)
{
C c(a);
assert(c.__invariants());
assert(c.empty());
assert(c.get_allocator() == a);
assert(is_contiguous_container_asan_correct(c));
}
int main()
{
{
test0<std::vector<int> >();
test0<std::vector<NotConstructible> >();
test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3));
test1<std::vector<NotConstructible, test_allocator<NotConstructible> > >
(test_allocator<NotConstructible>(5));
}
{
std::vector<int, stack_allocator<int, 10> > v;
assert(v.empty());
}
#if __cplusplus >= 201103L
{
test0<std::vector<int, min_allocator<int>> >();
test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >();
test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{});
test1<std::vector<NotConstructible, min_allocator<NotConstructible> > >
(min_allocator<NotConstructible>{});
}
{
std::vector<int, min_allocator<int> > v;
assert(v.empty());
}
#endif
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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 "test_iterators.h"
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C, class Iterator>
void
test(Iterator first, Iterator last)
{
C c(first, last);
assert(c.__invariants());
assert(c.size() == std::distance(first, last));
assert(is_contiguous_container_asan_correct(c));
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
assert(*i == *first);
}
int main()
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
test<std::vector<int> >(a, an);
test<std::vector<int, stack_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an));
test<std::vector<int, stack_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
test<std::vector<int, stack_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
test<std::vector<int, stack_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
test<std::vector<int, stack_allocator<int, 18> > >(a, an);
#if __cplusplus >= 201103L
test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
test<std::vector<int> >(a, an);
#endif
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// 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 "test_iterators.h"
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C, class Iterator, class A>
void
test(Iterator first, Iterator last, const A& a)
{
C c(first, last, a);
assert(c.__invariants());
assert(c.size() == std::distance(first, last));
assert(is_contiguous_container_asan_correct(c));
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
assert(*i == *first);
}
#if __cplusplus >= 201103L
template <class T>
struct implicit_conv_allocator : min_allocator<T>
{
implicit_conv_allocator(void* p) {}
implicit_conv_allocator(const implicit_conv_allocator&) = default;
};
#endif
int main()
{
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
std::allocator<int> alloc;
test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
test<std::vector<int> >(a, an, alloc);
}
#if __cplusplus >= 201103L
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
min_allocator<int> alloc;
test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(a, an, alloc);
test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr);
}
#endif
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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>
// explicit vector(size_type n);
#include <vector>
#include <cassert>
#include "DefaultOnly.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "asan_testing.h"
template <class C>
void
test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
{
#if _LIBCPP_STD_VER > 11
C c(n, a);
assert(c.__invariants());
assert(c.size() == n);
assert(c.get_allocator() == a);
assert(is_contiguous_container_asan_correct(c));
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
assert(*i == typename C::value_type());
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif
}
template <class C>
void
test1(typename C::size_type n)
{
C c(n);
assert(c.__invariants());
assert(c.size() == n);
assert(c.get_allocator() == typename C::allocator_type());
assert(is_contiguous_container_asan_correct(c));
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
assert(*i == typename C::value_type());
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
template <class C>
void
test(typename C::size_type n)
{
test1<C> ( n );
test2<C> ( n );
}
int main()
{
test<std::vector<int> >(50);
test<std::vector<DefaultOnly> >(500);
assert(DefaultOnly::count == 0);
#if __cplusplus >= 201103L
test<std::vector<int, min_allocator<int>> >(50);
test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
assert(DefaultOnly::count == 0);
#endif
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(size_type n, const value_type& x);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C>
void
test(typename C::size_type n, const typename C::value_type& x)
{
C c(n, x);
assert(c.__invariants());
assert(c.size() == n);
assert(is_contiguous_container_asan_correct(c));
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
assert(*i == x);
}
int main()
{
test<std::vector<int> >(50, 3);
test<std::vector<int, stack_allocator<int, 50> > >(50, 5);
#if __cplusplus >= 201103L
test<std::vector<int, min_allocator<int>> >(50, 3);
#endif
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(size_type n, const value_type& x, const allocator_type& a);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
template <class C>
void
test(typename C::size_type n, const typename C::value_type& x,
const typename C::allocator_type& a)
{
C c(n, x, a);
assert(c.__invariants());
assert(a == c.get_allocator());
assert(c.size() == n);
assert(is_contiguous_container_asan_correct(c));
for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
assert(*i == x);
}
int main()
{
test<std::vector<int> >(50, 3, std::allocator<int>());
#if __cplusplus >= 201103L
test<std::vector<int, min_allocator<int>> >(50, 3, min_allocator<int>());
#endif
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(const vector& v);
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C>
void
test(const C& x)
{
unsigned s = x.size();
C c(x);
assert(c.__invariants());
assert(c.size() == s);
assert(c == x);
assert(is_contiguous_container_asan_correct(c));
}
int main()
{
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<int>(a, an));
}
{
std::vector<int, test_allocator<int> > v(3, 2, test_allocator<int>(5));
std::vector<int, test_allocator<int> > v2 = v;
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
assert(v2 == v);
assert(v2.get_allocator() == v.get_allocator());
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
std::vector<int, other_allocator<int> > v(3, 2, other_allocator<int>(5));
std::vector<int, other_allocator<int> > v2 = v;
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
assert(v2 == v);
assert(v2.get_allocator() == other_allocator<int>(-2));
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
}
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
#if __cplusplus >= 201103L
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<int, min_allocator<int>>(a, an));
}
{
std::vector<int, min_allocator<int> > v(3, 2, min_allocator<int>());
std::vector<int, min_allocator<int> > v2 = v;
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
assert(v2 == v);
assert(v2.get_allocator() == v.get_allocator());
assert(is_contiguous_container_asan_correct(v));
assert(is_contiguous_container_asan_correct(v2));
}
#endif
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(const vector& v, const allocator_type& a);
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
template <class C>
void
test(const C& x, const typename C::allocator_type& a)
{
unsigned s = x.size();
C c(x, a);
assert(c.__invariants());
assert(c.size() == s);
assert(c == x);
assert(is_contiguous_container_asan_correct(c));
}
int main()
{
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<int>(a, an), std::allocator<int>());
}
{
std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5));
std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3));
assert(l2 == l);
assert(l2.get_allocator() == test_allocator<int>(3));
}
{
std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5));
std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<int>(3));
}
#if __cplusplus >= 201103L
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<int, min_allocator<int>>(a, an), min_allocator<int>());
}
{
std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>());
std::vector<int, min_allocator<int> > l2(l, min_allocator<int>());
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<int>());
}
#endif
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// 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>
// class vector
// vector();
#include <vector>
struct X
{
std::vector<X> q;
};
int main()
{
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector()
// noexcept(is_nothrow_default_constructible<allocator_type>::value);
// This tests a conforming extension
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc(const some_alloc&);
};
int main()
{
#if __has_feature(cxx_noexcept)
{
typedef std::vector<MoveOnly> C;
static_assert(std::is_nothrow_default_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_default_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
static_assert(!std::is_nothrow_default_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
static_assert(!std::is_nothrow_default_constructible<C>::value, "");
}
#endif
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// ~vector() // implied noexcept;
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
#if __has_feature(cxx_noexcept)
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc(const some_alloc&);
~some_alloc() noexcept(false);
};
#endif
int main()
{
#if __has_feature(cxx_noexcept)
{
typedef std::vector<MoveOnly> C;
static_assert(std::is_nothrow_destructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_destructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_destructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
static_assert(!std::is_nothrow_destructible<C>::value, "");
}
#endif
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(initializer_list<value_type> il);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int> d = {3, 4, 5, 6};
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> d = {3, 4, 5, 6};
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(initializer_list<value_type> il, const Allocator& a = allocator_type());
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3));
assert(d.get_allocator() == test_allocator<int>(3));
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>());
assert(d.get_allocator() == min_allocator<int>());
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,103 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(vector&& c);
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
{
std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
{
int a1[] = {1, 3, 7, 9, 10};
std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
assert(is_contiguous_container_asan_correct(c1));
std::vector<int>::const_iterator i = c1.begin();
std::vector<int> c2 = std::move(c1);
assert(is_contiguous_container_asan_correct(c2));
std::vector<int>::iterator j = c2.erase(i);
assert(*j == 3);
assert(is_contiguous_container_asan_correct(c2));
}
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
assert(is_contiguous_container_asan_correct(l2));
}
{
int a1[] = {1, 3, 7, 9, 10};
std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
assert(is_contiguous_container_asan_correct(c1));
std::vector<int, min_allocator<int>>::const_iterator i = c1.begin();
std::vector<int, min_allocator<int>> c2 = std::move(c1);
assert(is_contiguous_container_asan_correct(c2));
std::vector<int, min_allocator<int>>::iterator j = c2.erase(i);
assert(*j == 3);
assert(is_contiguous_container_asan_correct(c2));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(vector&& c, const allocator_type& a);
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6));
assert(l2 == lo);
assert(!l.empty());
assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
assert(is_contiguous_container_asan_correct(l2));
}
{
std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5));
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == test_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l2));
}
{
std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4));
assert(l2 == lo);
assert(!l.empty());
assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
assert(is_contiguous_container_asan_correct(l2));
}
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
assert(is_contiguous_container_asan_correct(l));
assert(is_contiguous_container_asan_correct(lo));
std::vector<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>());
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == min_allocator<MoveOnly>());
assert(is_contiguous_container_asan_correct(l2));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector& operator=(vector&& c)
// noexcept(
// allocator_type::propagate_on_container_move_assignment::value &&
// is_nothrow_move_assignable<allocator_type>::value);
// This tests a conforming extension
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc(const some_alloc&);
};
int main()
{
#if __has_feature(cxx_noexcept)
{
typedef std::vector<MoveOnly> C;
static_assert(std::is_nothrow_move_assignable<C>::value, "");
}
{
typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
}
{
typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_move_assignable<C>::value, "");
}
{
typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
}
#endif
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector(vector&&)
// noexcept(is_nothrow_move_constructible<allocator_type>::value);
// This tests a conforming extension
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc(const some_alloc&);
};
int main()
{
#if __has_feature(cxx_noexcept)
{
typedef std::vector<MoveOnly> C;
static_assert(std::is_nothrow_move_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_move_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
static_assert(std::is_nothrow_move_constructible<C>::value, "");
}
{
typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
static_assert(!std::is_nothrow_move_constructible<C>::value, "");
}
#endif
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// vector& operator=(initializer_list<value_type> il);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int> d;
d = {3, 4, 5, 6};
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> d;
d = {3, 4, 5, 6};
assert(d.size() == 4);
assert(is_contiguous_container_asan_correct(d));
assert(d[0] == 3);
assert(d[1] == 4);
assert(d[2] == 5);
assert(d[3] == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// pointer data();
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v;
assert(v.data() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int> v(100);
assert(v.data() == &v.front());
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v;
assert(v.data() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, min_allocator<int>> v(100);
assert(v.data() == &v.front());
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// const_pointer data() const;
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
const std::vector<int> v;
assert(v.data() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
const std::vector<int> v(100);
assert(v.data() == &v.front());
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
const std::vector<int, min_allocator<int>> v;
assert(v.data() == 0);
assert(is_contiguous_container_asan_correct(v));
}
{
const std::vector<int, min_allocator<int>> v(100);
assert(v.data() == &v.front());
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@@ -0,0 +1,160 @@
//===----------------------------------------------------------------------===//
//
// 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... Args> iterator emplace(const_iterator pos, Args&&... args);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
class A
{
int i_;
double d_;
A(const A&);
A& operator=(const A&);
public:
A(int i, double d)
: i_(i), d_(d) {}
A(A&& a)
: i_(a.i_),
d_(a.d_)
{
a.i_ = 0;
a.d_ = 0;
}
A& operator=(A&& a)
{
i_ = a.i_;
d_ = a.d_;
a.i_ = 0;
a.d_ = 0;
return *this;
}
int geti() const {return i_;}
double getd() const {return d_;}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<A> c;
std::vector<A>::iterator i = c.emplace(c.cbegin(), 2, 3.5);
assert(i == c.begin());
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(is_contiguous_container_asan_correct(c));
i = c.emplace(c.cend(), 3, 4.5);
assert(i == c.end()-1);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
i = c.emplace(c.cbegin()+1, 4, 6.5);
assert(i == c.begin()+1);
assert(c.size() == 3);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c[1].geti() == 4);
assert(c[1].getd() == 6.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
}
{
std::vector<A, stack_allocator<A, 7> > c;
std::vector<A, stack_allocator<A, 7> >::iterator i = c.emplace(c.cbegin(), 2, 3.5);
assert(i == c.begin());
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(is_contiguous_container_asan_correct(c));
i = c.emplace(c.cend(), 3, 4.5);
assert(i == c.end()-1);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
i = c.emplace(c.cbegin()+1, 4, 6.5);
assert(i == c.begin()+1);
assert(c.size() == 3);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c[1].geti() == 4);
assert(c[1].getd() == 6.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<A> c1;
std::vector<A> c2;
std::vector<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::vector<A, min_allocator<A>> c;
std::vector<A, min_allocator<A>>::iterator i = c.emplace(c.cbegin(), 2, 3.5);
assert(i == c.begin());
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
i = c.emplace(c.cend(), 3, 4.5);
assert(i == c.end()-1);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
i = c.emplace(c.cbegin()+1, 4, 6.5);
assert(i == c.begin()+1);
assert(c.size() == 3);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c[1].geti() == 4);
assert(c[1].getd() == 6.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<A, min_allocator<A>> c1;
std::vector<A, min_allocator<A>> c2;
std::vector<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
assert(false);
}
#endif
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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... Args> void emplace_back(Args&&... args);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
class A
{
int i_;
double d_;
A(const A&);
A& operator=(const A&);
public:
A(int i, double d)
: i_(i), d_(d) {}
A(A&& a)
: i_(a.i_),
d_(a.d_)
{
a.i_ = 0;
a.d_ = 0;
}
A& operator=(A&& a)
{
i_ = a.i_;
d_ = a.d_;
a.i_ = 0;
a.d_ = 0;
return *this;
}
int geti() const {return i_;}
double getd() const {return d_;}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<A> c;
c.emplace_back(2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(is_contiguous_container_asan_correct(c));
c.emplace_back(3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
}
{
std::vector<A, stack_allocator<A, 4> > c;
c.emplace_back(2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(is_contiguous_container_asan_correct(c));
c.emplace_back(3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
}
#if __cplusplus >= 201103L
{
std::vector<A, min_allocator<A>> c;
c.emplace_back(2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(is_contiguous_container_asan_correct(c));
c.emplace_back(3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
assert(is_contiguous_container_asan_correct(c));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// 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... Args> iterator emplace(const_iterator pos, Args&&... args);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int> v;
v.reserve(3);
assert(is_contiguous_container_asan_correct(v));
v = { 1, 2, 3 };
v.emplace(v.begin(), v.back());
assert(v[0] == 3);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int> v;
v.reserve(4);
assert(is_contiguous_container_asan_correct(v));
v = { 1, 2, 3 };
v.emplace(v.begin(), v.back());
assert(v[0] == 3);
assert(is_contiguous_container_asan_correct(v));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v;
v.reserve(3);
assert(is_contiguous_container_asan_correct(v));
v = { 1, 2, 3 };
v.emplace(v.begin(), v.back());
assert(v[0] == 3);
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<int, min_allocator<int>> v;
v.reserve(4);
assert(is_contiguous_container_asan_correct(v));
v = { 1, 2, 3 };
v.emplace(v.begin(), v.back());
assert(v[0] == 3);
assert(is_contiguous_container_asan_correct(v));
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator erase(const_iterator position);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int>::const_iterator i = l1.begin();
assert(is_contiguous_container_asan_correct(l1));
++i;
std::vector<int>::iterator j = l1.erase(i);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(*j == 3);
assert(*l1.begin() == 1);
assert(*next(l1.begin()) == 3);
assert(is_contiguous_container_asan_correct(l1));
j = l1.erase(j);
assert(j == l1.end());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(*l1.begin() == 1);
assert(is_contiguous_container_asan_correct(l1));
j = l1.erase(l1.begin());
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
assert(is_contiguous_container_asan_correct(l1));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(is_contiguous_container_asan_correct(l1));
++i;
std::vector<int, min_allocator<int>>::iterator j = l1.erase(i);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(*j == 3);
assert(*l1.begin() == 1);
assert(*next(l1.begin()) == 3);
assert(is_contiguous_container_asan_correct(l1));
j = l1.erase(j);
assert(j == l1.end());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(*l1.begin() == 1);
assert(is_contiguous_container_asan_correct(l1));
j = l1.erase(l1.begin());
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
assert(is_contiguous_container_asan_correct(l1));
}
#endif
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator position) with end()
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <cstdlib>
#include <exception>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int>::const_iterator i = l1.end();
l1.erase(i);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>>::const_iterator i = l1.end();
l1.erase(i);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator position) with iterator from another container
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <cstdlib>
#include <exception>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int> l2(a1, a1+3);
std::vector<int>::const_iterator i = l2.begin();
l1.erase(i);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>> l2(a1, a1+3);
std::vector<int, min_allocator<int>>::const_iterator i = l2.begin();
l1.erase(i);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,127 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator erase(const_iterator first, const_iterator last);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
int a1[] = {1, 2, 3};
{
std::vector<int> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
assert(l1.size() == 3);
assert(distance(l1.cbegin(), l1.cend()) == 3);
assert(i == l1.begin());
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin()));
assert(l1.size() == 2);
assert(distance(l1.cbegin(), l1.cend()) == 2);
assert(i == l1.begin());
assert(l1 == std::vector<int>(a1+1, a1+3));
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2));
assert(l1.size() == 1);
assert(distance(l1.cbegin(), l1.cend()) == 1);
assert(i == l1.begin());
assert(l1 == std::vector<int>(a1+2, a1+3));
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3));
assert(l1.size() == 0);
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<std::vector<int> > outer(2, std::vector<int>(1));
assert(is_contiguous_container_asan_correct(outer));
assert(is_contiguous_container_asan_correct(outer[0]));
assert(is_contiguous_container_asan_correct(outer[1]));
outer.erase(outer.begin(), outer.begin());
assert(outer.size() == 2);
assert(outer[0].size() == 1);
assert(outer[1].size() == 1);
assert(is_contiguous_container_asan_correct(outer));
assert(is_contiguous_container_asan_correct(outer[0]));
assert(is_contiguous_container_asan_correct(outer[1]));
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
assert(l1.size() == 3);
assert(distance(l1.cbegin(), l1.cend()) == 3);
assert(i == l1.begin());
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int, min_allocator<int>> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin()));
assert(l1.size() == 2);
assert(distance(l1.cbegin(), l1.cend()) == 2);
assert(i == l1.begin());
assert((l1 == std::vector<int, min_allocator<int>>(a1+1, a1+3)));
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int, min_allocator<int>> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2));
assert(l1.size() == 1);
assert(distance(l1.cbegin(), l1.cend()) == 1);
assert(i == l1.begin());
assert((l1 == std::vector<int, min_allocator<int>>(a1+2, a1+3)));
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<int, min_allocator<int>> l1(a1, a1+3);
assert(is_contiguous_container_asan_correct(l1));
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3));
assert(l1.size() == 0);
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
assert(is_contiguous_container_asan_correct(l1));
}
{
std::vector<std::vector<int, min_allocator<int>>, min_allocator<std::vector<int, min_allocator<int>>>> outer(2, std::vector<int, min_allocator<int>>(1));
assert(is_contiguous_container_asan_correct(outer));
assert(is_contiguous_container_asan_correct(outer[0]));
assert(is_contiguous_container_asan_correct(outer[1]));
outer.erase(outer.begin(), outer.begin());
assert(outer.size() == 2);
assert(outer[0].size() == 1);
assert(outer[1].size() == 1);
assert(is_contiguous_container_asan_correct(outer));
assert(is_contiguous_container_asan_correct(outer[0]));
assert(is_contiguous_container_asan_correct(outer[1]));
}
#endif
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator first, const_iterator last); with first iterator from another container
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int> l2(a1, a1+3);
std::vector<int>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>> l2(a1, a1+3);
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator first, const_iterator last); with second iterator from another container
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int> l2(a1, a1+3);
std::vector<int>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>> l2(a1, a1+3);
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator first, const_iterator last); with both iterators from another container
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int> l2(a1, a1+3);
std::vector<int>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>> l2(a1, a1+3);
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1);
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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>
// Call erase(const_iterator first, const_iterator last); with a bad range
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <vector>
#include <cassert>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::vector<int> l1(a1, a1+3);
std::vector<int>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin());
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::vector<int, min_allocator<int>> l1(a1, a1+3);
std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin());
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator insert(const_iterator p, initializer_list<value_type> il);
#include <vector>
#include <cassert>
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<int> d(10, 1);
std::vector<int>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6});
assert(d.size() == 14);
assert(is_contiguous_container_asan_correct(d));
assert(i == d.begin() + 2);
assert(d[0] == 1);
assert(d[1] == 1);
assert(d[2] == 3);
assert(d[3] == 4);
assert(d[4] == 5);
assert(d[5] == 6);
assert(d[6] == 1);
assert(d[7] == 1);
assert(d[8] == 1);
assert(d[9] == 1);
assert(d[10] == 1);
assert(d[11] == 1);
assert(d[12] == 1);
assert(d[13] == 1);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> d(10, 1);
std::vector<int, min_allocator<int>>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6});
assert(d.size() == 14);
assert(is_contiguous_container_asan_correct(d));
assert(i == d.begin() + 2);
assert(d[0] == 1);
assert(d[1] == 1);
assert(d[2] == 3);
assert(d[3] == 4);
assert(d[4] == 5);
assert(d[5] == 6);
assert(d[6] == 1);
assert(d[7] == 1);
assert(d[8] == 1);
assert(d[9] == 1);
assert(d[10] == 1);
assert(d[11] == 1);
assert(d[12] == 1);
assert(d[13] == 1);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,190 @@
//===----------------------------------------------------------------------===//
//
// 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 Iter>
// iterator insert(const_iterator position, Iter first, Iter last);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "test_iterators.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
forward_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
size_t sz = v.size();
int a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
forward_iterator<const int*>(a+N));
assert(v.size() == sz + N);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
v.reserve(128); // force no reallocation
size_t sz = v.size();
int a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
forward_iterator<const int*>(a+N));
assert(v.size() == sz + N);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int, stack_allocator<int, 308> > v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int, stack_allocator<int, 300> > v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
forward_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int> v(100);
std::vector<int> v2(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int, min_allocator<int>> v(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
forward_iterator<const int*>(a+N));
assert(v.size() == 100 + N);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int, min_allocator<int>> v(100);
std::vector<int, min_allocator<int>> v2(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(false);
}
#endif
#endif
}

View File

@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator insert(const_iterator position, value_type&& x);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "../../../MoveOnly.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly> v(100);
std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == MoveOnly());
assert(v[j] == MoveOnly(3));
for (++j; j < 101; ++j)
assert(v[j] == MoveOnly());
}
{
std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == MoveOnly());
assert(v[j] == MoveOnly(3));
for (++j; j < 101; ++j)
assert(v[j] == MoveOnly());
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int> v1(3);
std::vector<int> v2(3);
v1.insert(v2.begin(), 4);
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == MoveOnly());
assert(v[j] == MoveOnly(3));
for (++j; j < 101; ++j)
assert(v[j] == MoveOnly());
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int, min_allocator<int>> v1(3);
std::vector<int, min_allocator<int>> v2(3);
v1.insert(v2.begin(), 4);
assert(false);
}
#endif
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,132 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator insert(const_iterator position, size_type n, const value_type& x);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v(100);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == 105);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
size_t sz = v.size();
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == sz + 5);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
v.reserve(128); // force no reallocation
size_t sz = v.size();
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == sz + 5);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int, stack_allocator<int, 300> > v(100);
std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == 105);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int> c1(100);
std::vector<int> c2;
std::vector<int>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1);
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v(100);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == 105);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<int, min_allocator<int>> v(100);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == 105);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int, min_allocator<int>> c1(100);
std::vector<int, min_allocator<int>> c2;
std::vector<int, min_allocator<int>>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1);
assert(false);
}
#endif
#endif
}

View File

@@ -0,0 +1,116 @@
//===----------------------------------------------------------------------===//
//
// 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>
// iterator insert(const_iterator position, const value_type& x);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> v(100);
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < 101; ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
size_t sz = v.size();
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == sz + 1);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int> v(100);
while(v.size() < v.capacity()) v.push_back(0);
v.pop_back(); v.pop_back(); // force no reallocation
size_t sz = v.size();
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == sz + 1);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < v.size(); ++j)
assert(v[j] == 0);
}
{
std::vector<int, stack_allocator<int, 300> > v(100);
std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < 101; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int> v1(3);
std::vector<int> v2(3);
int i = 4;
v1.insert(v2.begin(), i);
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> v(100);
std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == 101);
assert(is_contiguous_container_asan_correct(v));
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < 101; ++j)
assert(v[j] == 0);
}
#if _LIBCPP_DEBUG >= 1
{
std::vector<int, min_allocator<int>> v1(3);
std::vector<int, min_allocator<int>> v2(3);
int i = 4;
v1.insert(v2.begin(), i);
assert(false);
}
#endif
#endif
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void pop_back();
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#if _LIBCPP_DEBUG >= 1
#include <cstdlib>
#include <exception>
#endif
int main()
{
{
std::vector<int> c;
c.push_back(1);
assert(c.size() == 1);
c.pop_back();
assert(c.size() == 0);
#if _LIBCPP_DEBUG >= 1
c.pop_back();
assert(false);
#endif
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> c;
c.push_back(1);
assert(c.size() == 1);
c.pop_back();
assert(c.size() == 0);
#if _LIBCPP_DEBUG >= 1
c.pop_back();
assert(false);
#endif
}
#endif
}

View File

@@ -0,0 +1,108 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void push_back(const value_type& x);
#include <vector>
#include <cassert>
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
std::vector<int> c;
c.push_back(0);
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(1);
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(2);
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(3);
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(4);
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
}
{
std::vector<int, stack_allocator<int, 15> > c;
c.push_back(0);
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(1);
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(2);
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(3);
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(4);
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
}
#if __cplusplus >= 201103L
{
std::vector<int, min_allocator<int>> c;
c.push_back(0);
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(1);
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(2);
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(3);
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
c.push_back(4);
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == j);
}
#endif
}

View File

@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void push_back(const value_type& x);
#include <vector>
#include <cassert>
#include "asan_testing.h"
// Flag that makes the copy constructor for CMyClass throw an exception
static bool gCopyConstructorShouldThow = false;
class CMyClass {
public: CMyClass(int tag);
public: CMyClass(const CMyClass& iOther);
public: ~CMyClass();
bool equal(const CMyClass &rhs) const
{ return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; }
private:
int fMagicValue;
int fTag;
private: static int kStartedConstructionMagicValue;
private: static int kFinishedConstructionMagicValue;
};
// Value for fMagicValue when the constructor has started running, but not yet finished
int CMyClass::kStartedConstructionMagicValue = 0;
// Value for fMagicValue when the constructor has finished running
int CMyClass::kFinishedConstructionMagicValue = 12345;
CMyClass::CMyClass(int tag) :
fMagicValue(kStartedConstructionMagicValue), fTag(tag)
{
// Signal that the constructor has finished running
fMagicValue = kFinishedConstructionMagicValue;
}
CMyClass::CMyClass(const CMyClass& iOther) :
fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag)
{
// If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue
if (gCopyConstructorShouldThow) {
throw std::exception();
}
// Signal that the constructor has finished running
fMagicValue = kFinishedConstructionMagicValue;
}
CMyClass::~CMyClass() {
// Only instances for which the constructor has finished running should be destructed
assert(fMagicValue == kFinishedConstructionMagicValue);
}
bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); }
int main()
{
CMyClass instance(42);
std::vector<CMyClass> vec;
vec.push_back(instance);
std::vector<CMyClass> vec2(vec);
assert(is_contiguous_container_asan_correct(vec));
assert(is_contiguous_container_asan_correct(vec2));
gCopyConstructorShouldThow = true;
try {
vec.push_back(instance);
}
catch (...) {
assert(vec==vec2);
assert(is_contiguous_container_asan_correct(vec));
}
}

View File

@@ -0,0 +1,111 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void push_back(value_type&& x);
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../stack_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::vector<MoveOnly> c;
c.push_back(MoveOnly(0));
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(1));
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(2));
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(3));
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(4));
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
}
{
std::vector<MoveOnly, stack_allocator<MoveOnly, 15> > c;
c.push_back(MoveOnly(0));
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(1));
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(2));
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(3));
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(4));
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
}
#if __cplusplus >= 201103L
{
std::vector<MoveOnly, min_allocator<MoveOnly>> c;
c.push_back(MoveOnly(0));
assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(1));
assert(c.size() == 2);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(2));
assert(c.size() == 3);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(3));
assert(c.size() == 4);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
c.push_back(MoveOnly(4));
assert(c.size() == 5);
assert(is_contiguous_container_asan_correct(c));
for (int j = 0; j < c.size(); ++j)
assert(c[j] == MoveOnly(j));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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 T, class Alloc>
// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <vector>
#include <cassert>
#include "min_allocator.h"
int main()
{
#if _LIBCPP_DEBUG >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::vector<int>::iterator i1 = c1.begin();
std::vector<int>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
c1.erase(i1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::vector<int, min_allocator<int>>::iterator i1 = c1.begin();
std::vector<int, min_allocator<int>>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
c1.erase(i1);
assert(false);
}
#endif
#endif
}

View File

@@ -0,0 +1,187 @@
//===----------------------------------------------------------------------===//
//
// 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 T, class Alloc>
// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y);
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
#include "asan_testing.h"
int main()
{
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0])));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int> c1(a1, a1);
std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int> c2(a2, a2);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0])));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int> c1(a1, a1);
std::vector<int> c2(a2, a2);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
#ifndef _LIBCPP_DEBUG_LEVEL
// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
typedef test_allocator<int> A;
std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1));
std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2));
swap(c1, c2);
assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c1.get_allocator() == A(1));
assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A(2));
}
#endif
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
typedef other_allocator<int> A;
std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1));
std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c1.get_allocator() == A(2));
assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A(1));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int, min_allocator<int>> c1(a1, a1);
std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::vector<int, min_allocator<int>> c2(a2, a2);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::vector<int, min_allocator<int>> c1(a1, a1);
std::vector<int, min_allocator<int>> c2(a2, a2);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
#ifndef _LIBCPP_DEBUG_LEVEL
// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
typedef min_allocator<int> A;
std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A());
std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A());
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
swap(c1, c2);
assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c1.get_allocator() == A());
assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A());
assert(is_contiguous_container_asan_correct(c1));
assert(is_contiguous_container_asan_correct(c2));
}
#endif
#endif
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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>
// void swap(vector& c)
// noexcept(!allocator_type::propagate_on_container_swap::value ||
// __is_nothrow_swappable<allocator_type>::value);
// This tests a conforming extension
#include <vector>
#include <cassert>
#include "../../../MoveOnly.h"
#include "test_allocator.h"
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc() {}
some_alloc(const some_alloc&);
void deallocate(void*, unsigned) {}
typedef std::true_type propagate_on_container_swap;
};
int main()
{
#if __has_feature(cxx_noexcept)
{
typedef std::vector<MoveOnly> C;
C c1, c2;
static_assert(noexcept(swap(c1, c2)), "");
}
{
typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
C c1, c2;
static_assert(noexcept(swap(c1, c2)), "");
}
{
typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
C c1, c2;
static_assert(noexcept(swap(c1, c2)), "");
}
{
typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
C c1, c2;
static_assert(!noexcept(swap(c1, c2)), "");
}
#endif
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <vector>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}