Finish converting list _LIBCPP_DEBUG tests.

llvm-svn: 273394
This commit is contained in:
Eric Fiselier 2016-06-22 08:47:43 +00:00
parent 3624fedb68
commit 75fd25e4bc
12 changed files with 206 additions and 118 deletions

View File

@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <list>
// list(list&& c);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <list>
#include <cstdlib>
#include <cassert>
int main()
{
std::list<int> l1 = {1, 2, 3};
std::list<int>::iterator i = l1.begin();
std::list<int> l2 = l1;
l2.erase(i);
assert(false);
}

View File

@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <list>
// list(list&& c);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(1))
#include <list>
#include <cstdlib>
#include <cassert>
#include "MoveOnly.h"
#include "test_allocator.h"
#include "min_allocator.h"
int main()
{
std::list<int> l1 = {1, 2, 3};
std::list<int>::iterator i = l1.begin();
std::list<int> l2 = std::move(l1);
assert(*l2.erase(i) == 2);
}

View File

@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <list>
// void splice(const_iterator position, list& x);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <list>
#include <cstdlib>
#include <cassert>
int main()
{
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v2.begin(), v2);
assert(false);
}
}

View File

@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <list>
// void splice(const_iterator position, list<T,Allocator>& x, iterator i);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <list>
#include <cstdlib>
#include <cassert>
int main()
{
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v1.begin(), v2, v1.begin());
assert(false);
}
}

View File

@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <list>
// void splice(const_iterator position, list& x, iterator first, iterator last);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <list>
#include <cstdlib>
#include <cassert>
int main()
{
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v1.begin(), v2, v2.begin(), v1.end());
assert(false);
}
}

View File

@ -12,48 +12,25 @@
// template <class T, class Alloc>
// void swap(list<T,Alloc>& x, list<T,Alloc>& y);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <list>
#include <cstdlib>
#include <cassert>
#include <__debug>
#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::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int>::iterator i1 = c1.begin();
std::list<int>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int>::iterator j = 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::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int, min_allocator<int>>::iterator i1 = c1.begin();
std::list<int, min_allocator<int>>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int, min_allocator<int>>::iterator j = i1;
c1.erase(i1);
assert(false);
}
#endif
#endif
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int>::iterator i1 = c1.begin();
std::list<int>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int>::iterator j = i1;
c1.erase(i1); // called with iterator not refering to list.
assert(false);
}

View File

@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <list>
// template <class T, class Alloc>
// void swap(list<T,Alloc>& x, list<T,Alloc>& y);
#define _LIBCPP_DEBUG 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <list>
#include <cassert>
#include "test_allocator.h"
#include "min_allocator.h"
int main()
{
// allocators do not compare equal
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
typedef test_allocator<int> A;
std::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1));
std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2));
swap(c1, c2);
assert(false);
}
}

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <list>
// list(list&& c);
@ -19,7 +21,6 @@
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
@ -46,7 +47,6 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#if TEST_STD_VER >= 11
{
std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
@ -60,15 +60,4 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#endif
#if _LIBCPP_DEBUG >= 1
{
std::list<int> l1 = {1, 2, 3};
std::list<int>::iterator i = l1.begin();
std::list<int> l2 = std::move(l1);
assert(*l2.erase(i) == 2);
assert(l2.size() == 2);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -11,13 +11,10 @@
// void splice(const_iterator position, list& x);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <list>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -403,14 +400,6 @@ int main()
++i;
assert(*i == 6);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v2.begin(), v2);
assert(false);
}
#endif
#if TEST_STD_VER >= 11
{
std::list<int, min_allocator<int>> l1;
@ -791,13 +780,5 @@ int main()
++i;
assert(*i == 6);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v2.begin(), v2);
assert(false);
}
#endif
#endif
}

View File

@ -11,13 +11,10 @@
// void splice(const_iterator position, list<T,Allocator>& x, iterator i);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <list>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -180,14 +177,6 @@ int main()
++i;
assert(*i == 2);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v1.begin(), v2, v1.begin());
assert(false);
}
#endif
#if TEST_STD_VER >= 11
{
std::list<int, min_allocator<int>> l1;
@ -345,13 +334,5 @@ int main()
++i;
assert(*i == 2);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v1.begin(), v2, v1.begin());
assert(false);
}
#endif
#endif
}

View File

@ -11,13 +11,10 @@
// void splice(const_iterator position, list& x, iterator first, iterator last);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <list>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main()
@ -120,14 +117,6 @@ int main()
i = l2.begin();
assert(*i == 4);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int> v1(3);
std::list<int> v2(3);
v1.splice(v1.begin(), v2, v2.begin(), v1.end());
assert(false);
}
#endif
#if TEST_STD_VER >= 11
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
@ -225,13 +214,5 @@ int main()
i = l2.begin();
assert(*i == 4);
}
#if _LIBCPP_DEBUG >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v1.begin(), v2, v2.begin(), v1.end());
assert(false);
}
#endif
#endif
}

View File

@ -59,21 +59,18 @@ int main()
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
}
#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::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1));
std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2));
std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(1));
swap(c1, c2);
assert((c1 == std::list<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c1.get_allocator() == A(1));
assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A(2));
assert(c2.get_allocator() == A(1));
}
#endif
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
@ -127,8 +124,6 @@ int main()
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
}
#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};
@ -142,5 +137,4 @@ int main()
assert(c2.get_allocator() == A());
}
#endif
#endif
}