forked from OSchip/llvm-project
Added debug tests for indexing, pop_back and both forms of erase. Added an improved error message for erasing a single element with end().
llvm-svn: 177929
This commit is contained in:
parent
a237239097
commit
ea1bbbd135
|
@ -1550,6 +1550,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __position)
|
|||
"vector::erase(iterator) called with an iterator not"
|
||||
" referring to this vector");
|
||||
#endif
|
||||
_LIBCPP_ASSERT(__position != end(),
|
||||
"vector::erase(iterator) called with a non-dereferenceable iterator");
|
||||
pointer __p = const_cast<pointer>(&*__position);
|
||||
iterator __r = __make_iter(__p);
|
||||
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
|
||||
|
|
|
@ -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>
|
||||
|
||||
// Index const vector out of bounds.
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
typedef int T;
|
||||
typedef std::vector<T> C;
|
||||
const C c(1);
|
||||
assert(c[0] == 0);
|
||||
assert(c[1] == 0);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Index vector out of bounds.
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
typedef int T;
|
||||
typedef std::vector<T> C;
|
||||
C c(1);
|
||||
assert(c[0] == 0);
|
||||
c.clear();
|
||||
assert(c[0] == 0);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Call erase(const_iterator position) with end()
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,45 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Call erase(const_iterator first, const_iterator last); with first iterator from another container
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Call erase(const_iterator first, const_iterator last); with second iterator from another container
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Call erase(const_iterator first, const_iterator last); with both iterators from another container
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// Call erase(const_iterator first, const_iterator last); with a bad range
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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>
|
||||
|
||||
// void pop_back();
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "../../../stack_allocator.h"
|
||||
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
std::set_terminate(f1);
|
||||
#endif
|
||||
{
|
||||
std::vector<int> c;
|
||||
c.push_back(1);
|
||||
assert(c.size() == 1);
|
||||
c.pop_back();
|
||||
assert(c.size() == 0);
|
||||
#if _LIBCPP_DEBUG2 >= 1
|
||||
c.pop_back();
|
||||
assert(false);
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue