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:
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// allocator:
|
||||
|
||||
// template <class T1, class T2>
|
||||
// bool
|
||||
// operator==(const allocator<T1>&, const allocator<T2>&) throw();
|
||||
//
|
||||
// template <class T1, class T2>
|
||||
// bool
|
||||
// operator!=(const allocator<T1>&, const allocator<T2>&) throw();
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::allocator<int> a1;
|
||||
std::allocator<int> a2;
|
||||
assert(a1 == a2);
|
||||
assert(!(a1 != a2));
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// allocator:
|
||||
// pointer address(reference x) const;
|
||||
// const_pointer address(const_reference x) const;
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
void test_address()
|
||||
{
|
||||
T* tp = new T();
|
||||
const T* ctp = tp;
|
||||
const std::allocator<T> a;
|
||||
assert(a.address(*tp) == tp);
|
||||
assert(a.address(*ctp) == tp);
|
||||
delete tp;
|
||||
}
|
||||
|
||||
struct A
|
||||
{
|
||||
void operator&() const {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
test_address<int>();
|
||||
test_address<A>();
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// allocator:
|
||||
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
assert(s == 3 * sizeof(int));
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
int A_constructed = 0;
|
||||
|
||||
struct A
|
||||
{
|
||||
int data;
|
||||
A() {++A_constructed;}
|
||||
A(const A&) {++A_constructed;}
|
||||
~A() {--A_constructed;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::allocator<A> a;
|
||||
assert(new_called == 0);
|
||||
assert(A_constructed == 0);
|
||||
A* ap = a.allocate(3);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
a.deallocate(ap, 3);
|
||||
assert(new_called == 0);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
A* ap2 = a.allocate(3, (const void*)5);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
a.deallocate(ap2, 3);
|
||||
assert(new_called == 0);
|
||||
assert(A_constructed == 0);
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// allocator:
|
||||
// template <class... Args> void construct(pointer p, Args&&... args);
|
||||
|
||||
// UNSUPPORTED: asan, msan
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
++new_called;
|
||||
assert(s == 3 * sizeof(int));
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
--new_called;
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
int A_constructed = 0;
|
||||
|
||||
struct A
|
||||
{
|
||||
int data;
|
||||
A() {++A_constructed;}
|
||||
|
||||
A(const A&) {++A_constructed;}
|
||||
|
||||
explicit A(int) {++A_constructed;}
|
||||
A(int, int*) {++A_constructed;}
|
||||
|
||||
~A() {--A_constructed;}
|
||||
};
|
||||
|
||||
int move_only_constructed = 0;
|
||||
|
||||
class move_only
|
||||
{
|
||||
int data;
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
move_only(const move_only&);
|
||||
move_only& operator=(const move_only&);
|
||||
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
move_only(move_only&);
|
||||
move_only& operator=(move_only&);
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
public:
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
move_only(move_only&&) {++move_only_constructed;}
|
||||
move_only& operator=(move_only&&) {return *this;}
|
||||
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
operator std::__rv<move_only> () {return std::__rv<move_only>(*this);}
|
||||
move_only(std::__rv<move_only>) {++move_only_constructed;}
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
move_only() {++move_only_constructed;}
|
||||
~move_only() {--move_only_constructed;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::allocator<A> a;
|
||||
assert(new_called == 0);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
A* ap = a.allocate(3);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
a.construct(ap);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
a.construct(ap, A());
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
a.construct(ap, 5);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
a.construct(ap, 5, (int*)0);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(A_constructed == 0);
|
||||
|
||||
a.deallocate(ap, 3);
|
||||
assert(new_called == 0);
|
||||
assert(A_constructed == 0);
|
||||
}
|
||||
{
|
||||
std::allocator<move_only> a;
|
||||
assert(new_called == 0);
|
||||
assert(move_only_constructed == 0);
|
||||
|
||||
move_only* ap = a.allocate(3);
|
||||
assert(new_called == 1);
|
||||
assert(move_only_constructed == 0);
|
||||
|
||||
a.construct(ap);
|
||||
assert(new_called == 1);
|
||||
assert(move_only_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(move_only_constructed == 0);
|
||||
|
||||
a.construct(ap, move_only());
|
||||
assert(new_called == 1);
|
||||
assert(move_only_constructed == 1);
|
||||
|
||||
a.destroy(ap);
|
||||
assert(new_called == 1);
|
||||
assert(move_only_constructed == 0);
|
||||
|
||||
a.deallocate(ap, 3);
|
||||
assert(new_called == 0);
|
||||
assert(move_only_constructed == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// allocator:
|
||||
// size_type max_size() const throw();
|
||||
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
|
||||
int new_called = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::allocator<int> a;
|
||||
std::size_t M = a.max_size() * sizeof(int);
|
||||
assert(M > 0xFFFF && M <= std::numeric_limits<std::size_t>::max());
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
// #include <memory>
|
||||
//
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc allocator_type;
|
||||
// typedef typename allocator_type::value_type
|
||||
// value_type;
|
||||
//
|
||||
// typedef Alloc::pointer | value_type* pointer;
|
||||
// typedef Alloc::const_pointer
|
||||
// | pointer_traits<pointer>::rebind<const value_type>
|
||||
// const_pointer;
|
||||
// typedef Alloc::void_pointer
|
||||
// | pointer_traits<pointer>::rebind<void>
|
||||
// void_pointer;
|
||||
// typedef Alloc::const_void_pointer
|
||||
// | pointer_traits<pointer>::rebind<const void>
|
||||
// const_void_pointer;
|
||||
|
||||
template <typename Alloc>
|
||||
void test_pointer()
|
||||
{
|
||||
typename std::allocator_traits<Alloc>::pointer vp;
|
||||
typename std::allocator_traits<Alloc>::const_pointer cvp;
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
|
||||
}
|
||||
|
||||
template <typename Alloc>
|
||||
void test_void_pointer()
|
||||
{
|
||||
typename std::allocator_traits<Alloc>::void_pointer vp;
|
||||
typename std::allocator_traits<Alloc>::const_void_pointer cvp;
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
|
||||
|
||||
static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
|
||||
static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
|
||||
}
|
||||
|
||||
struct Foo { int x; };
|
||||
|
||||
int main()
|
||||
{
|
||||
test_pointer<std::allocator<char>> ();
|
||||
test_pointer<std::allocator<int>> ();
|
||||
test_pointer<std::allocator<Foo>> ();
|
||||
|
||||
test_void_pointer<std::allocator<char>> ();
|
||||
test_void_pointer<std::allocator<int>> ();
|
||||
test_void_pointer<std::allocator<Foo>> ();
|
||||
}
|
||||
#else
|
||||
int main() {}
|
||||
#endif
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// check nested types:
|
||||
|
||||
// template <class T>
|
||||
// class allocator
|
||||
// {
|
||||
// public:
|
||||
// typedef size_t size_type;
|
||||
// typedef ptrdiff_t difference_type;
|
||||
// typedef T* pointer;
|
||||
// typedef const T* const_pointer;
|
||||
// typedef typename add_lvalue_reference<T>::type reference;
|
||||
// typedef typename add_lvalue_reference<const T>::type const_reference;
|
||||
// typedef T value_type;
|
||||
//
|
||||
// template <class U> struct rebind {typedef allocator<U> other;};
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::value_type, char>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
|
||||
static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
|
||||
std::allocator<int> >::value), "");
|
||||
std::allocator<char> a;
|
||||
std::allocator<char> a2 = a;
|
||||
a2 = a;
|
||||
std::allocator<int> a3 = a2;
|
||||
}
|
@@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <>
|
||||
// class allocator<void>
|
||||
// {
|
||||
// public:
|
||||
// typedef void* pointer;
|
||||
// typedef const void* const_pointer;
|
||||
// typedef void value_type;
|
||||
//
|
||||
// template <class _Up> struct rebind {typedef allocator<_Up> other;};
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
|
||||
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
|
||||
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
|
||||
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
|
||||
std::allocator<int> >::value), "");
|
||||
std::allocator<void> a;
|
||||
std::allocator<void> a2 = a;
|
||||
a2 = a;
|
||||
}
|
Reference in New Issue
Block a user