More vector::iterator debug mode tests. Run by adding to OPTIONS -D_LIBCPP_DEBUG2=1.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@177897 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2013-03-25 20:03:19 +00:00
parent f5f4684e71
commit 0d01eb54e7
8 changed files with 346 additions and 7 deletions

View File

@ -9,12 +9,7 @@
// <vector>
// iterator begin();
// iterator end();
// const_iterator begin() const;
// const_iterator end() const;
// const_iterator cbegin() const;
// const_iterator cend() const;
// Compare iterators from different containers with == or !=.
#if _LIBCPP_DEBUG2 >= 1
@ -50,4 +45,4 @@ int main()
{
}
#endif
#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>
// Compare iterators from different containers with <.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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 c1;
C c2;
bool b = c1.begin() < c2.begin();
assert(false);
}
#else
int main()
{
}
#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>
// Subtract iterators from different containers.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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 c1;
C c2;
int i = c1.begin() - c2.begin();
assert(false);
}
#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>
// Index iterator out of bounds.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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);
C::iterator i = c.begin();
assert(i[0] == 0);
assert(i[1] == 0);
assert(false);
}
#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>
// Add to iterator out of bounds.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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);
C::iterator i = c.begin();
i += 1;
assert(i == c.end());
i = c.begin();
i += 2;
assert(false);
}
#else
int main()
{
}
#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>
// Decrement iterator prior to begin.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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);
C::iterator i = c.end();
--i;
assert(i == c.begin());
--i;
assert(false);
}
#else
int main()
{
}
#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>
// Increment iterator past end.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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);
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#else
int main()
{
}
#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>
// Dereference non-dereferenceable iterator.
#if _LIBCPP_DEBUG2 >= 1
struct X {};
#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);
C::iterator i = c.end();
T j = *i;
assert(false);
}
#else
int main()
{
}
#endif