diff options
Diffstat (limited to 'test/std/utilities')
845 files changed, 44858 insertions, 0 deletions
diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp new file mode 100644 index 0000000000000..a5663a2e063e7 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class OuterA2> +// scoped_allocator_adaptor(OuterA2&& outerAlloc, +// const InnerAllocs& ...innerAllocs); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A1<int> a3(3); + A a(a3); + assert(a.outer_allocator() == A1<int>(3)); + assert(a.inner_allocator() == a); + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + } + A1<int>::copy_called = false; + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a(A1<int>(3)); + assert(a.outer_allocator() == A1<int>(3)); + assert(a.inner_allocator() == a); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + } + A1<int>::move_called = false; + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A1<int> a4(4); + A a(a4, A2<int>(5)); + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(a.outer_allocator() == A1<int>(4)); + assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5))); + } + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a(A1<int>(4), A2<int>(5)); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(a.outer_allocator() == A1<int>(4)); + assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5))); + } + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A1<int>::move_called = false; + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A1<int> a4(4); + A a(a4, A2<int>(5), A3<int>(6)); + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(A3<int>::copy_called == true); + assert(A3<int>::move_called == false); + assert(a.outer_allocator() == A1<int>(4)); + assert((a.inner_allocator() == + std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6)))); + } + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A3<int>::copy_called = false; + A3<int>::move_called = false; + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a(A1<int>(4), A2<int>(5), A3<int>(6)); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(A3<int>::copy_called == true); + assert(A3<int>::move_called == false); + assert(a.outer_allocator() == A1<int>(4)); + assert((a.inner_allocator() == + std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6)))); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp new file mode 100644 index 0000000000000..9d40cf55a144a --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class OuterA2> +// scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, +// InnerAllocs...>& other); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<double>> B; + typedef std::scoped_allocator_adaptor<A1<int>> A; + B a1(A1<int>(3)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<double>, A2<int>> B; + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + B a1(A1<int>(4), A2<int>(5)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(A2<int>::copy_called == true); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<double>, A2<int>, A3<int>> B; + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + B a1(A1<int>(4), A2<int>(5), A3<int>(6)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A3<int>::copy_called = false; + A3<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(A2<int>::copy_called == true); + assert(A3<int>::copy_called == true); + assert(a2 == a1); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp new file mode 100644 index 0000000000000..02e9dff7d7d38 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class OuterA2> +// scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2, +// InnerAllocs...>&& other); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<double>> B; + typedef std::scoped_allocator_adaptor<A1<int>> A; + B a1(A1<int>(3)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A a2 = std::move(a1); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<double>, A2<int>> B; + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + B a1(A1<int>(4), A2<int>(5)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A a2 = std::move(a1); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + assert(A2<int>::copy_called == false); + assert(A2<int>::move_called == true); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<double>, A2<int>, A3<int>> B; + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + B a1(A1<int>(4), A2<int>(5), A3<int>(6)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A3<int>::copy_called = false; + A3<int>::move_called = false; + A a2 = std::move(a1); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == true); + assert(A2<int>::copy_called == false); + assert(A2<int>::move_called == true); + assert(A3<int>::copy_called == false); + assert(A3<int>::move_called == true); + assert(a2 == a1); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp new file mode 100644 index 0000000000000..21055325112fa --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// scoped_allocator_adaptor(const scoped_allocator_adaptor& other); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a1(A1<int>(3)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a1(A1<int>(4), A2<int>(5)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(a2 == a1); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a1(A1<int>(4), A2<int>(5), A3<int>(6)); + A1<int>::copy_called = false; + A1<int>::move_called = false; + A2<int>::copy_called = false; + A2<int>::move_called = false; + A3<int>::copy_called = false; + A3<int>::move_called = false; + A a2 = a1; + assert(A1<int>::copy_called == true); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == true); + assert(A2<int>::move_called == false); + assert(A3<int>::copy_called == true); + assert(A3<int>::move_called == false); + assert(a2 == a1); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp new file mode 100644 index 0000000000000..2a1d781eb9cd8 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// scoped_allocator_adaptor(); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a; + assert(a.outer_allocator() == A1<int>()); + assert(a.inner_allocator() == a); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == false); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a; + assert(a.outer_allocator() == A1<int>()); + assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>()); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == false); + assert(A2<int>::move_called == false); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a; + assert(a.outer_allocator() == A1<int>()); + assert((a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>, A3<int>>())); + assert(A1<int>::copy_called == false); + assert(A1<int>::move_called == false); + assert(A2<int>::copy_called == false); + assert(A2<int>::move_called == false); + assert(A3<int>::copy_called == false); + assert(A3<int>::move_called == false); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp new file mode 100644 index 0000000000000..727907e3ec76a --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp @@ -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> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// pointer allocate(size_type n); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10) == (int*)10); + assert(A1<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10) == (int*)10); + assert(A1<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10) == (int*)10); + assert(A1<int>::allocate_called == true); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp new file mode 100644 index 0000000000000..cae42de669058 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// pointer allocate(size_type n, const_void_pointer hint); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10, (const void*)0) == (int*)10); + assert(A1<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10, (const void*)10) == (int*)10); + assert(A1<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a; + A1<int>::allocate_called = false; + assert(a.allocate(10, (const void*)20) == (int*)10); + assert(A1<int>::allocate_called == true); + } + + { + typedef std::scoped_allocator_adaptor<A2<int>> A; + A a; + A2<int>::allocate_called = false; + assert(a.allocate(10, (const void*)0) == (int*)0); + assert(A2<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A2<int>, A2<int>> A; + A a; + A2<int>::allocate_called = false; + assert(a.allocate(10, (const void*)10) == (int*)10); + assert(A2<int>::allocate_called == true); + } + { + typedef std::scoped_allocator_adaptor<A2<int>, A2<int>, A3<int>> A; + A a; + A2<int>::allocate_called = false; + assert(a.allocate(10, (const void*)20) == (int*)20); + assert(A2<int>::allocate_called == true); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp new file mode 100644 index 0000000000000..f94b0e19ac901 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp @@ -0,0 +1,193 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class T, class... Args> void construct(T* p, Args&&... args); + +#include <scoped_allocator> +#include <cassert> +#include <string> + +#include "allocators.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +struct B +{ + static bool constructed; + + typedef A1<B> allocator_type; + + explicit B(std::allocator_arg_t, const allocator_type& a, int i) + { + assert(a.id() == 5); + assert(i == 6); + constructed = true; + } +}; + +bool B::constructed = false; + +struct C +{ + static bool constructed; + + typedef std::scoped_allocator_adaptor<A2<C>> allocator_type; + + explicit C(std::allocator_arg_t, const allocator_type& a, int i) + { + assert(a.id() == 7); + assert(i == 8); + constructed = true; + } +}; + +bool C::constructed = false; + +struct D +{ + static bool constructed; + + typedef std::scoped_allocator_adaptor<A2<D>> allocator_type; + + explicit D(int i, int j, const allocator_type& a) + { + assert(i == 1); + assert(j == 2); + assert(a.id() == 3); + constructed = true; + } +}; + +bool D::constructed = false; + +struct E +{ + static bool constructed; + + typedef std::scoped_allocator_adaptor<A1<E>> allocator_type; + + explicit E(int i, int j, const allocator_type& a) + { + assert(i == 1); + assert(j == 2); + assert(a.id() == 50); + constructed = true; + } +}; + +bool E::constructed = false; + +struct F +{ + static bool constructed; + + typedef std::scoped_allocator_adaptor<A2<F>> allocator_type; + + explicit F(int i, int j) + { + assert(i == 1); + assert(j == 2); + } + + explicit F(int i, int j, const allocator_type& a) + { + assert(i == 1); + assert(j == 2); + assert(a.id() == 50); + constructed = true; + } +}; + +bool F::constructed = false; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<std::string>> A; + A a; + char buf[100]; + typedef std::string S; + S* s = (S*)buf; + a.construct(s, 4, 'c'); + assert(*s == "cccc"); + s->~S(); + } + + { + typedef std::scoped_allocator_adaptor<A1<B>> A; + A a(A1<B>(5)); + char buf[100]; + typedef B S; + S* s = (S*)buf; + a.construct(s, 6); + assert(S::constructed); + s->~S(); + } + + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<C>> A; + A a(A1<int>(5), A2<C>(7)); + char buf[100]; + typedef C S; + S* s = (S*)buf; + a.construct(s, 8); + assert(S::constructed); + s->~S(); + } + + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<D>> A; + A a(A1<int>(5), A2<D>(3)); + char buf[100]; + typedef D S; + S* s = (S*)buf; + a.construct(s, 1, 2); + assert(S::constructed); + s->~S(); + } + + { + typedef std::scoped_allocator_adaptor<A3<E>, A2<E>> K; + typedef std::scoped_allocator_adaptor<K, A1<E>> A; + A a(K(), A1<E>(50)); + char buf[100]; + typedef E S; + S* s = (S*)buf; + A3<E>::constructed = false; + a.construct(s, 1, 2); + assert(S::constructed); + assert(A3<E>::constructed); + s->~S(); + } + + { + typedef std::scoped_allocator_adaptor<A3<F>, A2<F>> K; + typedef std::scoped_allocator_adaptor<K, A1<F>> A; + A a(K(), A1<F>(50)); + char buf[100]; + typedef F S; + S* s = (S*)buf; + A3<F>::constructed = false; + a.construct(s, 1, 2); + assert(!S::constructed); + assert(A3<F>::constructed); + s->~S(); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp new file mode 100644 index 0000000000000..bf77f29f71450 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// void deallocate(pointer p, size_type n); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a; + a.deallocate((int*)10, 20); + assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20))); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a; + a.deallocate((int*)10, 20); + assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20))); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a; + a.deallocate((int*)10, 20); + assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20))); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp new file mode 100644 index 0000000000000..0ff3880f9fc19 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class T> void destroy(T* p); + +#include <scoped_allocator> +#include <cassert> +#include <string> + +#include "allocators.h" + +struct B +{ + static bool constructed; + + B() {constructed = true;} + ~B() {constructed = false;} +}; + +bool B::constructed = false; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<B>> A; + A a; + char buf[100]; + typedef B S; + S* s = (S*)buf; + assert(!S::constructed); + a.construct(s); + assert(S::constructed); + a.destroy(s); + assert(!S::constructed); + } + + { + typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A; + A a; + char buf[100]; + typedef B S; + S* s = (S*)buf; + assert(!S::constructed); + assert(!A3<S>::constructed); + assert(!A3<S>::destroy_called); + a.construct(s); + assert(S::constructed); + assert(A3<S>::constructed); + assert(!A3<S>::destroy_called); + a.destroy(s); + assert(!S::constructed); + assert(A3<S>::constructed); + assert(A3<S>::destroy_called); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp new file mode 100644 index 0000000000000..0fb55b692cdb4 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// inner_allocator_type& inner_allocator(); +// const inner_allocator_type& inner_allocator() const; + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a(A1<int>(5)); + assert(a.inner_allocator() == a); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a(A1<int>(5), A2<int>(6)); + assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(6))); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a(A1<int>(5), A2<int>(6), A3<int>(8)); + assert((a.inner_allocator() == + std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(6), A3<int>(8)))); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp new file mode 100644 index 0000000000000..a5275ee30253f --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// size_type max_size() const; + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + const A a(A1<int>(100)); + assert(a.max_size() == 100); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + const A a(A1<int>(20), A2<int>()); + assert(a.max_size() == 20); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + const A a(A1<int>(200), A2<int>(), A3<int>()); + assert(a.max_size() == 200); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp new file mode 100644 index 0000000000000..2297612e6098e --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// outer_allocator_type& outer_allocator(); +// const outer_allocator_type& outer_allocator() const; + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a(A1<int>(5)); + assert(a.outer_allocator() == A1<int>(5)); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a(A1<int>(5), A2<int>(6)); + assert(a.outer_allocator() == A1<int>(5)); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a(A1<int>(5), A2<int>(6), A3<int>(8)); + assert(a.outer_allocator() == A1<int>(5)); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp new file mode 100644 index 0000000000000..f9f0ffa2ad2ac --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// scoped_allocator_adaptor select_on_container_copy_construction() const; + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a1(A1<int>(3)); + assert(a1.outer_allocator().id() == 3); + A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1); + assert(a2.outer_allocator().id() == 3); + } + + { + typedef std::scoped_allocator_adaptor<A3<int>> A; + A a1(A3<int>(3)); + assert(a1.outer_allocator().id() == 3); + A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1); + assert(a2.outer_allocator().id() == -1); + } + + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a1(A1<int>(1), A2<int>(2), A3<int>(3)); + assert(a1.outer_allocator().id() == 1); + assert(a1.inner_allocator().outer_allocator().id() == 2); + assert(a1.inner_allocator().inner_allocator().outer_allocator().id() == 3); + A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1); + assert(a2.outer_allocator().id() == 1); + assert(a2.inner_allocator().outer_allocator().id() == 2); + assert(a2.inner_allocator().inner_allocator().outer_allocator().id() == -1); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp new file mode 100644 index 0000000000000..e165d9836db00 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// 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 <scoped_allocator> +#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::scoped_allocator_adaptor<std::allocator<char>>> (); + test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); + test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); + + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); +} +#else +int main() {} +#endif diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp new file mode 100644 index 0000000000000..4303b95166c77 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp @@ -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> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// typedef see below inner_allocator_type; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::inner_allocator_type, + std::scoped_allocator_adaptor<A1<int>>>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>>::inner_allocator_type, + std::scoped_allocator_adaptor<A2<int>>>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::inner_allocator_type, + std::scoped_allocator_adaptor<A2<int>, A3<int>>>::value), ""); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/is_always_equal.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/is_always_equal.pass.cpp new file mode 100644 index 0000000000000..e19e731f6cf2b --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/is_always_equal.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// typedef see below is_always_equal; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + // sanity checks + static_assert( (std::is_same< + std::allocator_traits<A1<int>>::is_always_equal, std::false_type>::value + ), "" ); + + static_assert( (std::is_same< + std::allocator_traits<min_allocator<int>>::is_always_equal, std::true_type>::value + ), "" ); + + // wrapping one allocator + static_assert( + (std::is_same< + std::scoped_allocator_adaptor<A1<int>>::is_always_equal, + std::allocator_traits<A1<int>>::is_always_equal + >::value), ""); + + // wrapping one allocator + static_assert( + (std::is_same< + std::scoped_allocator_adaptor<min_allocator<int>>::is_always_equal, + std::allocator_traits<min_allocator<int>>::is_always_equal + >::value), ""); + + // wrapping two allocators (check the values instead of the types) + static_assert(( + std::scoped_allocator_adaptor<A1<int>, A2<int>>::is_always_equal::value == + ( std::allocator_traits<A1<int>>::is_always_equal::value && + std::allocator_traits<A2<int>>::is_always_equal::value) + ), ""); + + // wrapping two allocators (check the values instead of the types) + static_assert(( + std::scoped_allocator_adaptor<A1<int>, min_allocator<int>>::is_always_equal::value == + ( std::allocator_traits<A1<int>>::is_always_equal::value && + std::allocator_traits<min_allocator<int>>::is_always_equal::value) + ), ""); + + + // wrapping three allocators (check the values instead of the types) + static_assert(( + std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::is_always_equal::value == + ( std::allocator_traits<A1<int>>::is_always_equal::value && + std::allocator_traits<A2<int>>::is_always_equal::value && + std::allocator_traits<A3<int>>::is_always_equal::value) + ), ""); + + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp new file mode 100644 index 0000000000000..ceb941380dc7f --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp @@ -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> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// typedef see below propagate_on_container_copy_assignment; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_copy_assignment, + std::false_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_copy_assignment, + std::false_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_copy_assignment, + std::true_type>::value), ""); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp new file mode 100644 index 0000000000000..04da507065361 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp @@ -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> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// typedef see below propagate_on_container_move_assignment; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_move_assignment, + std::false_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_move_assignment, + std::true_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_move_assignment, + std::true_type>::value), ""); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp new file mode 100644 index 0000000000000..4a66bbd46749c --- /dev/null +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp @@ -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> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// typedef see below propagate_on_container_swap; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::propagate_on_container_swap, + std::false_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>>::propagate_on_container_swap, + std::false_type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_swap, + std::true_type>::value), ""); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/scoped.adaptor.operators/eq.pass.cpp b/test/std/utilities/allocator.adaptor/scoped.adaptor.operators/eq.pass.cpp new file mode 100644 index 0000000000000..8d4cb6abe84a0 --- /dev/null +++ b/test/std/utilities/allocator.adaptor/scoped.adaptor.operators/eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor + +// template <class OuterA1, class OuterA2, class... InnerAllocs> +// bool +// operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, +// const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b); +// +// template <class OuterA1, class OuterA2, class... InnerAllocs> +// bool +// operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, +// const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b); + +#include <scoped_allocator> +#include <cassert> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + { + typedef std::scoped_allocator_adaptor<A1<int>> A; + A a1(A1<int>(3)); + A a2 = a1; + assert(a2 == a1); + assert(!(a2 != a1)); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; + A a1(A1<int>(4), A2<int>(5)); + A a2 = a1; + assert(a2 == a1); + assert(!(a2 != a1)); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a1(A1<int>(4), A2<int>(5), A3<int>(6)); + A a2 = a1; + assert(a2 == a1); + assert(!(a2 != a1)); + } + { + typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; + A a1(A1<int>(4), A2<int>(5), A3<int>(6)); + A a2(A1<int>(4), A2<int>(5), A3<int>(5)); + assert(a2 != a1); + assert(!(a2 == a1)); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/allocator.adaptor/types.pass.cpp b/test/std/utilities/allocator.adaptor/types.pass.cpp new file mode 100644 index 0000000000000..7beff48bbf46f --- /dev/null +++ b/test/std/utilities/allocator.adaptor/types.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// 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 OuterAlloc, class... InnerAllocs> +// class scoped_allocator_adaptor +// : public OuterAlloc +// { +// public: +// typedef OuterAlloc outer_allocator_type; +// typedef typename OuterTraits::size_type size_type; +// typedef typename OuterTraits::difference_type difference_type; +// typedef typename OuterTraits::pointer pointer; +// typedef typename OuterTraits::const_pointer const_pointer; +// typedef typename OuterTraits::void_pointer void_pointer; +// typedef typename OuterTraits::const_void_pointer const_void_pointer; +// }; + +#include <scoped_allocator> +#include <type_traits> + +#include "allocators.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert((std::is_base_of< + A1<int>, + std::scoped_allocator_adaptor<A1<int>> + >::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::outer_allocator_type, + A1<int>>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::size_type, + std::make_unsigned<std::ptrdiff_t>::type>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::difference_type, + std::ptrdiff_t>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::pointer, + int*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::const_pointer, + const int*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::void_pointer, + void*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A1<int>>::const_void_pointer, + const void*>::value), ""); + + static_assert((std::is_base_of< + A2<int>, + std::scoped_allocator_adaptor<A2<int>, A1<int>> + >::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::outer_allocator_type, + A2<int>>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::size_type, + unsigned>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::difference_type, + int>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::pointer, + int*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_pointer, + const int*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::void_pointer, + void*>::value), ""); + + static_assert((std::is_same< + std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_void_pointer, + const void*>::value), ""); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/date.time/asctime.thread-unsafe.fail.cpp b/test/std/utilities/date.time/asctime.thread-unsafe.fail.cpp new file mode 100644 index 0000000000000..3a9749e21c528 --- /dev/null +++ b/test/std/utilities/date.time/asctime.thread-unsafe.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-thread-unsafe-c-functions + +#include <ctime> + +int main() { + // asctime is not thread-safe. + std::time_t t = 0; + std::asctime(&t); +} diff --git a/test/std/utilities/date.time/ctime.thread-unsafe.fail.cpp b/test/std/utilities/date.time/ctime.thread-unsafe.fail.cpp new file mode 100644 index 0000000000000..cd246c6315270 --- /dev/null +++ b/test/std/utilities/date.time/ctime.thread-unsafe.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-thread-unsafe-c-functions + +#include <ctime> + +int main() { + // ctime is not thread-safe. + std::time_t t = 0; + std::ctime(&t); +} diff --git a/test/std/utilities/date.time/gmtime.thread-unsafe.fail.cpp b/test/std/utilities/date.time/gmtime.thread-unsafe.fail.cpp new file mode 100644 index 0000000000000..a6debcbd98d87 --- /dev/null +++ b/test/std/utilities/date.time/gmtime.thread-unsafe.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-thread-unsafe-c-functions + +#include <ctime> + +int main() { + // gmtime is not thread-safe. + std::time_t t = 0; + std::gmtime(&t); +} diff --git a/test/std/utilities/date.time/localtime.thread-unsafe.fail.cpp b/test/std/utilities/date.time/localtime.thread-unsafe.fail.cpp new file mode 100644 index 0000000000000..c9e55c8fd3a69 --- /dev/null +++ b/test/std/utilities/date.time/localtime.thread-unsafe.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-thread-unsafe-c-functions + +#include <ctime> + +int main() { + // localtime is not thread-safe. + std::time_t t = 0; + std::localtime(&t); +} diff --git a/test/std/utilities/date.time/tested_elsewhere.pass.cpp b/test/std/utilities/date.time/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..419f415dee19a --- /dev/null +++ b/test/std/utilities/date.time/tested_elsewhere.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 <ctime> +#include <type_traits> + +#ifndef NULL +#error NULL not defined +#endif + +#ifndef CLOCKS_PER_SEC +#error CLOCKS_PER_SEC not defined +#endif + +int main() +{ + std::clock_t c = 0; + ((void)c); // avoid unused warning + std::size_t s = 0; + std::time_t t = 0; + std::tm tm = {0}; + char str[3]; + static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); + static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); + static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); + static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); + static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); + static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); + static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), ""); + static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), ""); + static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), ""); +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp new file mode 100644 index 0000000000000..490dc16b60e21 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// divides + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::divides<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(36, 4) == 9); +#if _LIBCPP_STD_VER > 11 + typedef std::divides<> F2; + const F2 f2 = F2(); + assert(f2(36, 4) == 9); + assert(f2(36.0, 4) == 9); + assert(f2(18, 4.0) == 4.5); // exact in binary + + constexpr int foo = std::divides<int> () (3, 2); + static_assert ( foo == 1, "" ); + + constexpr int bar = std::divides<> () (3.0, 2); + static_assert ( bar == 1, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp new file mode 100644 index 0000000000000..9bda541f896a8 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// minus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::minus<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(3, 2) == 1); +#if _LIBCPP_STD_VER > 11 + typedef std::minus<> F2; + const F2 f2 = F2(); + assert(f2(3,2) == 1); + assert(f2(3.0, 2) == 1); + assert(f2(3, 2.5) == 0.5); + + constexpr int foo = std::minus<int> () (3, 2); + static_assert ( foo == 1, "" ); + + constexpr int bar = std::minus<> () (3.0, 2); + static_assert ( bar == 1, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp new file mode 100644 index 0000000000000..ca5bba6d5b8ea --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/modulus.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// modulus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::modulus<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(36, 8) == 4); +#if _LIBCPP_STD_VER > 11 + typedef std::modulus<> F2; + const F2 f2 = F2(); + assert(f2(36, 8) == 4); + assert(f2(36L, 8) == 4); + assert(f2(36, 8L) == 4); + + constexpr int foo = std::modulus<int> () (3, 2); + static_assert ( foo == 1, "" ); + + constexpr int bar = std::modulus<> () (3L, 2); + static_assert ( bar == 1, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp new file mode 100644 index 0000000000000..f132c8d4bd9b2 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// multiplies + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::multiplies<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(3, 2) == 6); +#if _LIBCPP_STD_VER > 11 + typedef std::multiplies<> F2; + const F2 f2 = F2(); + assert(f2(3,2) == 6); + assert(f2(3.0, 2) == 6); + assert(f2(3, 2.5) == 7.5); // exact in binary + + constexpr int foo = std::multiplies<int> () (3, 2); + static_assert ( foo == 6, "" ); + + constexpr int bar = std::multiplies<> () (3.0, 2); + static_assert ( bar == 6, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp new file mode 100644 index 0000000000000..0adac659123b4 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::negate<int> F; + const F f = F(); + static_assert((std::is_same<F::argument_type, int>::value), "" ); + static_assert((std::is_same<F::result_type, int>::value), "" ); + assert(f(36) == -36); +#if _LIBCPP_STD_VER > 11 + typedef std::negate<> F2; + const F2 f2 = F2(); + assert(f2(36) == -36); + assert(f2(36L) == -36); + assert(f2(36.0) == -36); + + constexpr int foo = std::negate<int> () (3); + static_assert ( foo == -3, "" ); + + constexpr int bar = std::negate<> () (3.0); + static_assert ( bar == -3, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp new file mode 100644 index 0000000000000..3c093fc093c32 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// plus + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::plus<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(3, 2) == 5); +#if _LIBCPP_STD_VER > 11 + typedef std::plus<> F2; + const F2 f2 = F2(); + assert(f2(3,2) == 5); + assert(f2(3.0, 2) == 5); + assert(f2(3, 2.5) == 5.5); + + constexpr int foo = std::plus<int> () (3, 2); + static_assert ( foo == 5, "" ); + + constexpr int bar = std::plus<> () (3.0, 2); + static_assert ( bar == 5, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp b/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp new file mode 100644 index 0000000000000..72b4b4a0a1fe7 --- /dev/null +++ b/test/std/utilities/function.objects/arithmetic.operations/transparent.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 <functional> +#include <string> + +template <class _Tp> +struct is_transparent +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::is_transparent* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + + +int main () { +#if _LIBCPP_STD_VER > 11 + + static_assert ( !is_transparent<std::plus<int>>::value, "" ); + static_assert ( !is_transparent<std::plus<std::string>>::value, "" ); + static_assert ( is_transparent<std::plus<void>>::value, "" ); + static_assert ( is_transparent<std::plus<>>::value, "" ); + + static_assert ( !is_transparent<std::minus<int>>::value, "" ); + static_assert ( !is_transparent<std::minus<std::string>>::value, "" ); + static_assert ( is_transparent<std::minus<void>>::value, "" ); + static_assert ( is_transparent<std::minus<>>::value, "" ); + + static_assert ( !is_transparent<std::multiplies<int>>::value, "" ); + static_assert ( !is_transparent<std::multiplies<std::string>>::value, "" ); + static_assert ( is_transparent<std::multiplies<void>>::value, "" ); + static_assert ( is_transparent<std::multiplies<>>::value, "" ); + + static_assert ( !is_transparent<std::divides<int>>::value, "" ); + static_assert ( !is_transparent<std::divides<std::string>>::value, "" ); + static_assert ( is_transparent<std::divides<void>>::value, "" ); + static_assert ( is_transparent<std::divides<>>::value, "" ); + + static_assert ( !is_transparent<std::modulus<int>>::value, "" ); + static_assert ( !is_transparent<std::modulus<std::string>>::value, "" ); + static_assert ( is_transparent<std::modulus<void>>::value, "" ); + static_assert ( is_transparent<std::modulus<>>::value, "" ); + + static_assert ( !is_transparent<std::negate<int>>::value, "" ); + static_assert ( !is_transparent<std::negate<std::string>>::value, "" ); + static_assert ( is_transparent<std::negate<void>>::value, "" ); + static_assert ( is_transparent<std::negate<>>::value, "" ); + +#endif + + return 0; + } diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp new file mode 100644 index 0000000000000..6315598125c9f --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +// http://llvm.org/bugs/show_bug.cgi?id=16385 + +#include <functional> +#include <cmath> +#include <cassert> + +float _pow(float a, float b) +{ + return std::pow(a, b); +} + +int main() +{ + std::function<float(float, float)> fnc = _pow; + auto task = std::bind(fnc, 2.f, 4.f); + auto task2(task); + assert(task() == 16); + assert(task2() == 16); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp new file mode 100644 index 0000000000000..33bf01855908c --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +// http://llvm.org/bugs/show_bug.cgi?id=22003 + +#include <functional> + +struct DummyUnaryFunction +{ + template <typename S> + int operator()(S const & s) const { return 0; } +}; + +struct BadUnaryFunction +{ + template <typename S> + constexpr int operator()(S const & s) const + { + // Trigger a compile error if this function is instantiated. + // The constexpr is needed so that it is instantiated while checking + // __invoke_of<BadUnaryFunction &, ...>. + static_assert(!std::is_same<S, S>::value, "Shit"); + return 0; + } +}; + +int main(int argc, char* argv[]) +{ + // Check that BadUnaryFunction::operator()(S const &) is not + // instantiated when checking if BadUnaryFunction is a nested bind + // expression during b(0). See PR22003. + auto b = std::bind(DummyUnaryFunction(), BadUnaryFunction()); + b(0); + auto b2 = std::bind<long>(DummyUnaryFunction(), BadUnaryFunction()); + b2(0); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp new file mode 100644 index 0000000000000..ab4dd59534d5e --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <functional> +#include <cassert> + +template <class R, class F> +void +test(F f, R expected) +{ + assert(f() == expected); +} + +template <class R, class F> +void +test_const(const F& f, R expected) +{ + assert(f() == expected); +} + +int f() {return 1;} + +struct A_int_0 +{ + int operator()() {return 4;} + int operator()() const {return 5;} +}; + +int main() +{ + test(std::bind(f), 1); + test(std::bind(&f), 1); + test(std::bind(A_int_0()), 4); + test_const(std::bind(A_int_0()), 5); + + test(std::bind<int>(f), 1); + test(std::bind<int>(&f), 1); + test(std::bind<int>(A_int_0()), 4); + test_const(std::bind<int>(A_int_0()), 5); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp new file mode 100644 index 0000000000000..af5efe464d5d2 --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp @@ -0,0 +1,287 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <stdio.h> + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {count += 2;} +}; + +void +test_void_1() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + int i = 2; + std::bind(f_void_1, _1)(i); + assert(count == save_count + 2); + save_count = count; + } + { + int i = 2; + std::bind(f_void_1, i)(); + assert(count == save_count + 2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + int i = 3; + std::bind(fp, _1)(i); + assert(count == save_count+3); + save_count = count; + } + { + void (*fp)(int) = f_void_1; + int i = 3; + std::bind(fp, i)(); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + int i = 4; + std::bind(a0, _1)(i); + assert(count == save_count+4); + save_count = count; + } + { + A_void_1 a0; + int i = 4; + std::bind(a0, i)(); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + A_void_1 a; + std::bind(fp, _1)(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, _1)(ap); + assert(count == save_count+1); + save_count = count; + } + { + void (A_void_1::*fp)() = &A_void_1::mem1; + A_void_1 a; + std::bind(fp, a)(); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, ap)(); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + A_void_1 a; + std::bind(fp, _1)(a); + assert(count == save_count+2); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, _1)(ap); + assert(count == save_count+2); + save_count = count; + } + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + A_void_1 a; + std::bind(fp, a)(); + assert(count == save_count+2); + save_count = count; + A_void_1* ap = &a; + std::bind(fp, ap)(); + assert(count == save_count+2); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + using namespace std::placeholders; + // function + { + int i = 2; + assert(std::bind(f_int_1, _1)(i) == 3); + assert(std::bind(f_int_1, i)() == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + int i = 3; + assert(std::bind(fp, _1)(i) == 4); + assert(std::bind(fp, i)() == 4); + } + // functor + { + int i = 4; + assert(std::bind(A_int_1(), _1)(i) == 3); + assert(std::bind(A_int_1(), i)() == 3); + } + // member function pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::mem1, _1)(a) == 3); + assert(std::bind(&A_int_1::mem1, a)() == 3); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::mem1, _1)(ap) == 3); + assert(std::bind(&A_int_1::mem1, ap)() == 3); + } + // const member function pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4); + assert(std::bind(&A_int_1::mem2, A_int_1())() == 4); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::mem2, _1)(ap) == 4); + assert(std::bind(&A_int_1::mem2, ap)() == 4); + } + // member data pointer + { + A_int_1 a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + assert(std::bind(&A_int_1::data_, a)() == 5); + A_int_1* ap = &a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + std::bind(&A_int_1::data_, _1)(a) = 6; + assert(std::bind(&A_int_1::data_, _1)(a) == 6); + assert(std::bind(&A_int_1::data_, _1)(ap) == 6); + std::bind(&A_int_1::data_, _1)(ap) = 7; + assert(std::bind(&A_int_1::data_, _1)(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + int i = 2; + int j = 3; + std::bind(f_void_2, _1, _2)(i, j); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, i, _1)(j); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, i, j)(); + assert(count == save_count+5); + save_count = count; + } + // member function pointer + { + int j = 3; + std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), j); + assert(count == save_count+3); + save_count = count; + std::bind(&A_void_2::mem1, _2, _1)(j, A_void_2()); + assert(count == save_count+3); + save_count = count; + } +} + +struct TFENode +{ + bool foo(unsigned long long) const + { + return true; + } +}; + +void +test3() +{ + using namespace std; + using namespace std::placeholders; + const auto f = bind(&TFENode::foo, _1, 0UL); + const TFENode n = TFENode{}; + bool b = f(n); + assert(b); +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp new file mode 100644 index 0000000000000..4913a510c36ee --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp @@ -0,0 +1,266 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <stdio.h> + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {count += 2;} +}; + +void +test_void_1() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + std::bind(f_void_1, _1)(2); + assert(count == save_count + 2); + save_count = count; + } + { + std::bind(f_void_1, 2)(); + assert(count == save_count + 2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::bind(fp, _1)(3); + assert(count == save_count+3); + save_count = count; + } + { + void (*fp)(int) = f_void_1; + std::bind(fp, 3)(); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::bind(a0, _1)(4); + assert(count == save_count+4); + save_count = count; + } + { + A_void_1 a0; + std::bind(a0, 4)(); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::bind(fp, _1)(A_void_1()); + assert(count == save_count+1); + save_count = count; + A_void_1 a; + std::bind(fp, _1)(&a); + assert(count == save_count+1); + save_count = count; + } + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::bind(fp, A_void_1())(); + assert(count == save_count+1); + save_count = count; + A_void_1 a; + std::bind(fp, &a)(); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::bind(fp, _1)(A_void_1()); + assert(count == save_count+2); + save_count = count; + A_void_1 a; + std::bind(fp, _1)(&a); + assert(count == save_count+2); + save_count = count; + } + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::bind(fp, A_void_1())(); + assert(count == save_count+2); + save_count = count; + A_void_1 a; + std::bind(fp, &a)(); + assert(count == save_count+2); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + using namespace std::placeholders; + // function + { + assert(std::bind(f_int_1, _1)(2) == 3); + assert(std::bind(f_int_1, 2)() == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + assert(std::bind(fp, _1)(3) == 4); + assert(std::bind(fp, 3)() == 4); + } + // functor + { + assert(std::bind(A_int_1(), _1)(4) == 3); + assert(std::bind(A_int_1(), 4)() == 3); + } + // member function pointer + { + assert(std::bind(&A_int_1::mem1, _1)(A_int_1()) == 3); + assert(std::bind(&A_int_1::mem1, A_int_1())() == 3); + A_int_1 a; + assert(std::bind(&A_int_1::mem1, _1)(&a) == 3); + assert(std::bind(&A_int_1::mem1, &a)() == 3); + } + // const member function pointer + { + assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4); + assert(std::bind(&A_int_1::mem2, A_int_1())() == 4); + A_int_1 a; + assert(std::bind(&A_int_1::mem2, _1)(&a) == 4); + assert(std::bind(&A_int_1::mem2, &a)() == 4); + } + // member data pointer + { + assert(std::bind(&A_int_1::data_, _1)(A_int_1()) == 5); + assert(std::bind(&A_int_1::data_, A_int_1())() == 5); + A_int_1 a; + assert(std::bind(&A_int_1::data_, _1)(a) == 5); + std::bind(&A_int_1::data_, _1)(a) = 6; + assert(std::bind(&A_int_1::data_, _1)(a) == 6); + assert(std::bind(&A_int_1::data_, _1)(&a) == 6); + std::bind(&A_int_1::data_, _1)(&a) = 7; + assert(std::bind(&A_int_1::data_, _1)(&a) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + using namespace std::placeholders; + int save_count = count; + // function + { + std::bind(f_void_2, _1, _2)(2, 3); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, 2, _1)(3); + assert(count == save_count+5); + save_count = count; + std::bind(f_void_2, 2, 3)(); + assert(count == save_count+5); + save_count = count; + } + // member function pointer + { + std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), 3); + assert(count == save_count+3); + save_count = count; + std::bind(&A_void_2::mem1, _2, _1)(3, A_void_2()); + assert(count == save_count+3); + save_count = count; + } +} + +int f_nested(int i) +{ + return i+1; +} + +int g_nested(int i) +{ + return i*10; +} + +void test_nested() +{ + using namespace std::placeholders; + assert(std::bind(f_nested, std::bind(g_nested, _1))(3) == 31); +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + test_nested(); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp new file mode 100644 index 0000000000000..b7874b77cf036 --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +#include <functional> +#include <cassert> + +int count = 0; + +template <class F> +void +test(F f) +{ + int save_count = count; + f(); + assert(count == save_count + 1); +} + +template <class F> +void +test_const(const F& f) +{ + int save_count = count; + f(); + assert(count == save_count + 2); +} + +void f() {++count;} + +int g() {++count; return 0;} + +struct A_void_0 +{ + void operator()() {++count;} + void operator()() const {count += 2;} +}; + +struct A_int_0 +{ + int operator()() {++count; return 4;} + int operator()() const {count += 2; return 5;} +}; + +int main() +{ + test(std::bind(f)); + test(std::bind(&f)); + test(std::bind(A_void_0())); + test_const(std::bind(A_void_0())); + + test(std::bind<void>(f)); + test(std::bind<void>(&f)); + test(std::bind<void>(A_void_0())); + test_const(std::bind<void>(A_void_0())); + + test(std::bind<void>(g)); + test(std::bind<void>(&g)); + test(std::bind<void>(A_int_0())); + test_const(std::bind<void>(A_int_0())); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp new file mode 100644 index 0000000000000..12720f7b550a0 --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); +// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> +// unspecified bind(Fn, Types...); + +// http://llvm.org/bugs/show_bug.cgi?id=16343 + +#include <cmath> +#include <functional> +#include <cassert> + +struct power +{ + template <typename T> + T + operator()(T a, T b) + { + return std::pow(a, b); + } +}; + +struct plus_one +{ + template <typename T> + T + operator()(T a) + { + return a + 1; + } +}; + +int +main() +{ + using std::placeholders::_1; + + auto g = std::bind(power(), 2, _1); + assert(g(5) == 32); + assert(std::bind(plus_one(), g)(5) == 33); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp new file mode 100644 index 0000000000000..7f8dd4a98d2b0 --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<class T> struct is_bind_expression + +#include <functional> + +template <bool Expected, class T> +void +test(const T&) +{ + static_assert(std::is_bind_expression<T>::value == Expected, ""); +} + +struct C {}; + +int main() +{ + test<true>(std::bind(C())); + test<true>(std::bind(C(), std::placeholders::_2)); + test<true>(std::bind<int>(C())); + test<false>(1); + test<false>(std::placeholders::_2); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp new file mode 100644 index 0000000000000..6a52bd1848e9b --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// struct is_placeholder + +#include <functional> + +template <int Expected, class T> +void +test(const T&) +{ + static_assert(std::is_placeholder<T>::value == Expected, ""); +} + +struct C {}; + +int main() +{ + test<1>(std::placeholders::_1); + test<2>(std::placeholders::_2); + test<3>(std::placeholders::_3); + test<4>(std::placeholders::_4); + test<5>(std::placeholders::_5); + test<6>(std::placeholders::_6); + test<7>(std::placeholders::_7); + test<8>(std::placeholders::_8); + test<9>(std::placeholders::_9); + test<10>(std::placeholders::_10); + test<0>(4); + test<0>(5.5); + test<0>('a'); + test<0>(C()); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp new file mode 100644 index 0000000000000..246186040c56e --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// placeholders + +#include <functional> +#include <type_traits> + +template <class T> +void +test(const T& t) +{ + // Test default constructible. + T t2; + ((void)t2); + // Test copy constructible. + T t3 = t; + ((void)t3); + static_assert(std::is_nothrow_copy_constructible<T>::value, ""); + static_assert(std::is_nothrow_move_constructible<T>::value, ""); +} + +int main() +{ + test(std::placeholders::_1); + test(std::placeholders::_2); + test(std::placeholders::_3); + test(std::placeholders::_4); + test(std::placeholders::_5); + test(std::placeholders::_6); + test(std::placeholders::_7); + test(std::placeholders::_8); + test(std::placeholders::_9); + test(std::placeholders::_10); +} diff --git a/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/function.objects/bind/nothing_to_do.pass.cpp b/test/std/utilities/function.objects/bind/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/function.objects/bind/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/function.objects/bitwise.operations/bit_and.pass.cpp b/test/std/utilities/function.objects/bitwise.operations/bit_and.pass.cpp new file mode 100644 index 0000000000000..c0135fad19827 --- /dev/null +++ b/test/std/utilities/function.objects/bitwise.operations/bit_and.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_and + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::bit_and<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(0xEA95, 0xEA95) == 0xEA95); + assert(f(0xEA95, 0x58D3) == 0x4891); + assert(f(0x58D3, 0xEA95) == 0x4891); + assert(f(0x58D3, 0) == 0); + assert(f(0xFFFF, 0x58D3) == 0x58D3); +#if _LIBCPP_STD_VER > 11 + typedef std::bit_and<> F2; + const F2 f2 = F2(); + assert(f2(0xEA95, 0xEA95) == 0xEA95); + assert(f2(0xEA95L, 0xEA95) == 0xEA95); + assert(f2(0xEA95, 0xEA95L) == 0xEA95); + + assert(f2(0xEA95, 0x58D3) == 0x4891); + assert(f2(0xEA95L, 0x58D3) == 0x4891); + assert(f2(0xEA95, 0x58D3L) == 0x4891); + + assert(f2(0x58D3, 0xEA95) == 0x4891); + assert(f2(0x58D3L, 0xEA95) == 0x4891); + assert(f2(0x58D3, 0xEA95L) == 0x4891); + + assert(f2(0x58D3, 0) == 0); + assert(f2(0x58D3L, 0) == 0); + assert(f2(0x58D3, 0L) == 0); + + assert(f2(0xFFFF, 0x58D3) == 0x58D3); + assert(f2(0xFFFFL, 0x58D3) == 0x58D3); + assert(f2(0xFFFF, 0x58D3L) == 0x58D3); + + constexpr int foo = std::bit_and<int> () (0x58D3, 0xEA95); + static_assert ( foo == 0x4891, "" ); + + constexpr int bar = std::bit_and<> () (0x58D3L, 0xEA95); + static_assert ( bar == 0x4891, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/bitwise.operations/bit_not.pass.cpp b/test/std/utilities/function.objects/bitwise.operations/bit_not.pass.cpp new file mode 100644 index 0000000000000..48800a366a81c --- /dev/null +++ b/test/std/utilities/function.objects/bitwise.operations/bit_not.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_not + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::bit_not<int> F; + const F f = F(); + static_assert((std::is_same<F::argument_type, int>::value), "" ); + static_assert((std::is_same<F::result_type, int>::value), "" ); + assert((f(0xEA95) & 0xFFFF ) == 0x156A); + assert((f(0x58D3) & 0xFFFF ) == 0xA72C); + assert((f(0) & 0xFFFF ) == 0xFFFF); + assert((f(0xFFFF) & 0xFFFF ) == 0); + + typedef std::bit_not<> F2; + const F2 f2 = F2(); + assert((f2(0xEA95) & 0xFFFF ) == 0x156A); + assert((f2(0xEA95L) & 0xFFFF ) == 0x156A); + assert((f2(0x58D3) & 0xFFFF ) == 0xA72C); + assert((f2(0x58D3L) & 0xFFFF ) == 0xA72C); + assert((f2(0) & 0xFFFF ) == 0xFFFF); + assert((f2(0L) & 0xFFFF ) == 0xFFFF); + assert((f2(0xFFFF) & 0xFFFF ) == 0); + assert((f2(0xFFFFL) & 0xFFFF ) == 0); + + constexpr int foo = std::bit_not<int> () (0xEA95) & 0xFFFF; + static_assert ( foo == 0x156A, "" ); + + constexpr int bar = std::bit_not<> () (0xEA95) & 0xFFFF; + static_assert ( bar == 0x156A, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/bitwise.operations/bit_or.pass.cpp b/test/std/utilities/function.objects/bitwise.operations/bit_or.pass.cpp new file mode 100644 index 0000000000000..cb33df3d84b7f --- /dev/null +++ b/test/std/utilities/function.objects/bitwise.operations/bit_or.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_or + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::bit_or<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(0xEA95, 0xEA95) == 0xEA95); + assert(f(0xEA95, 0x58D3) == 0xFAD7); + assert(f(0x58D3, 0xEA95) == 0xFAD7); + assert(f(0x58D3, 0) == 0x58D3); + assert(f(0xFFFF, 0x58D3) == 0xFFFF); +#if _LIBCPP_STD_VER > 11 + typedef std::bit_or<> F2; + const F2 f2 = F2(); + assert(f2(0xEA95, 0xEA95) == 0xEA95); + assert(f2(0xEA95L, 0xEA95) == 0xEA95); + assert(f2(0xEA95, 0xEA95L) == 0xEA95); + + assert(f2(0xEA95, 0x58D3) == 0xFAD7); + assert(f2(0xEA95L, 0x58D3) == 0xFAD7); + assert(f2(0xEA95, 0x58D3L) == 0xFAD7); + + assert(f2(0x58D3, 0xEA95) == 0xFAD7); + assert(f2(0x58D3L, 0xEA95) == 0xFAD7); + assert(f2(0x58D3, 0xEA95L) == 0xFAD7); + + assert(f2(0x58D3, 0) == 0x58D3); + assert(f2(0x58D3L, 0) == 0x58D3); + assert(f2(0x58D3, 0L) == 0x58D3); + + assert(f2(0xFFFF, 0x58D3) == 0xFFFF); + assert(f2(0xFFFFL, 0x58D3) == 0xFFFF); + assert(f2(0xFFFF, 0x58D3L) == 0xFFFF); + + constexpr int foo = std::bit_or<int> () (0x58D3, 0xEA95); + static_assert ( foo == 0xFAD7, "" ); + + constexpr int bar = std::bit_or<> () (0x58D3L, 0xEA95); + static_assert ( bar == 0xFAD7, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp b/test/std/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp new file mode 100644 index 0000000000000..bbf2ce5baf1bb --- /dev/null +++ b/test/std/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// bit_xor + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + { + typedef std::bit_xor<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<int, F::result_type>::value), "" ); + assert(f(0xEA95, 0xEA95) == 0); + assert(f(0xEA95, 0x58D3) == 0xB246); + assert(f(0x58D3, 0xEA95) == 0xB246); + assert(f(0x58D3, 0) == 0x58D3); + assert(f(0xFFFF, 0x58D3) == 0xA72C); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::bit_xor<> F2; + const F2 f = F2(); + assert(f(0xEA95, 0xEA95) == 0); + assert(f(0xEA95L, 0xEA95) == 0); + assert(f(0xEA95, 0xEA95L) == 0); + + assert(f(0xEA95, 0x58D3) == 0xB246); + assert(f(0xEA95L, 0x58D3) == 0xB246); + assert(f(0xEA95, 0x58D3L) == 0xB246); + + assert(f(0x58D3, 0xEA95) == 0xB246); + assert(f(0x58D3L, 0xEA95) == 0xB246); + assert(f(0x58D3, 0xEA95L) == 0xB246); + + assert(f(0x58D3, 0) == 0x58D3); + assert(f(0x58D3L, 0) == 0x58D3); + assert(f(0x58D3, 0L) == 0x58D3); + + assert(f(0xFFFF, 0x58D3) == 0xA72C); + assert(f(0xFFFFL, 0x58D3) == 0xA72C); + assert(f(0xFFFF, 0x58D3L) == 0xA72C); + + constexpr int foo = std::bit_xor<int> () (0x58D3, 0xEA95); + static_assert ( foo == 0xB246, "" ); + + constexpr int bar = std::bit_xor<> () (0x58D3L, 0xEA95); + static_assert ( bar == 0xB246, "" ); + } +#endif +} diff --git a/test/std/utilities/function.objects/bitwise.operations/transparent.pass.cpp b/test/std/utilities/function.objects/bitwise.operations/transparent.pass.cpp new file mode 100644 index 0000000000000..9f8e15dd55fe0 --- /dev/null +++ b/test/std/utilities/function.objects/bitwise.operations/transparent.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +#include <functional> +#include <string> + +template <class _Tp> +struct is_transparent +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::is_transparent* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + + +int main () { +#if _LIBCPP_STD_VER > 11 + + static_assert ( !is_transparent<std::bit_and<int>>::value, "" ); + static_assert ( !is_transparent<std::bit_and<std::string>>::value, "" ); + static_assert ( is_transparent<std::bit_and<void>>::value, "" ); + static_assert ( is_transparent<std::bit_and<>>::value, "" ); + + static_assert ( !is_transparent<std::bit_or<int>>::value, "" ); + static_assert ( !is_transparent<std::bit_or<std::string>>::value, "" ); + static_assert ( is_transparent<std::bit_or<void>>::value, "" ); + static_assert ( is_transparent<std::bit_or<>>::value, "" ); + + static_assert ( !is_transparent<std::bit_xor<int>>::value, "" ); + static_assert ( !is_transparent<std::bit_xor<std::string>>::value, "" ); + static_assert ( is_transparent<std::bit_xor<void>>::value, "" ); + static_assert ( is_transparent<std::bit_xor<>>::value, "" ); + + static_assert ( !is_transparent<std::bit_not<int>>::value, "" ); + static_assert ( !is_transparent<std::bit_not<std::string>>::value, "" ); + static_assert ( is_transparent<std::bit_not<void>>::value, "" ); + static_assert ( is_transparent<std::bit_not<>>::value, "" ); + +#endif + + return 0; + } diff --git a/test/std/utilities/function.objects/comparisons/equal_to.pass.cpp b/test/std/utilities/function.objects/comparisons/equal_to.pass.cpp new file mode 100644 index 0000000000000..60415ec75d60f --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/equal_to.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::equal_to<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(f(36, 36)); + assert(!f(36, 6)); +#if _LIBCPP_STD_VER > 11 + typedef std::equal_to<> F2; + const F2 f2 = F2(); + assert(f2(36, 36)); + assert(!f2(36, 6)); + assert(f2(36, 36.0)); + assert(f2(36.0, 36L)); + + constexpr bool foo = std::equal_to<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::equal_to<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/greater.pass.cpp b/test/std/utilities/function.objects/comparisons/greater.pass.cpp new file mode 100644 index 0000000000000..164f09aa605cc --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/greater.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// greater + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(!f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::greater<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert(f2(36, 6)); + assert(!f2(6, 36)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(6, 36.0)); + assert(!f2(6.0, 36)); + + constexpr bool foo = std::greater<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::greater<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/greater_equal.pass.cpp b/test/std/utilities/function.objects/comparisons/greater_equal.pass.cpp new file mode 100644 index 0000000000000..e89c14e246259 --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/greater_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// greater_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::greater_equal<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(f(36, 36)); + assert(f(36, 6)); + assert(!f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::greater_equal<> F2; + const F2 f2 = F2(); + assert(f2(36, 36)); + assert(f2(36, 6)); + assert(!f2(6, 36)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(6, 36.0)); + assert(!f2(6.0, 36)); + + constexpr bool foo = std::greater_equal<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::greater_equal<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/less.pass.cpp b/test/std/utilities/function.objects/comparisons/less.pass.cpp new file mode 100644 index 0000000000000..74fe166a0cd96 --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/less.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// less + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(!f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::less<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert(!f2(36, 6)); + assert( f2(6, 36)); + assert(!f2(36, 6.0)); + assert(!f2(36.0, 6)); + assert( f2(6, 36.0)); + assert( f2(6.0, 36)); + + constexpr bool foo = std::less<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::less<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/less_equal.pass.cpp b/test/std/utilities/function.objects/comparisons/less_equal.pass.cpp new file mode 100644 index 0000000000000..e6ba1f7f8a212 --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/less_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// less_equal + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::less_equal<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(f(36, 36)); + assert(!f(36, 6)); + assert(f(6, 36)); +#if _LIBCPP_STD_VER > 11 + typedef std::less_equal<> F2; + const F2 f2 = F2(); + assert( f2(36, 36)); + assert(!f2(36, 6)); + assert( f2(6, 36)); + assert(!f2(36, 6.0)); + assert(!f2(36.0, 6)); + assert( f2(6, 36.0)); + assert( f2(6.0, 36)); + + constexpr bool foo = std::less_equal<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::less_equal<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp b/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp new file mode 100644 index 0000000000000..3e710b3e0c70b --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/not_equal_to.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not_equal_to + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::not_equal_to<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(!f(36, 36)); + assert(f(36, 6)); +#if _LIBCPP_STD_VER > 11 + typedef std::not_equal_to<> F2; + const F2 f2 = F2(); + assert(!f2(36, 36)); + assert( f2(36, 6)); + assert( f2(36, 6.0)); + assert( f2(36.0, 6)); + assert(!f2(36.0, 36)); + assert(!f2(36, 36.0)); + + constexpr bool foo = std::not_equal_to<int> () (36, 36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::not_equal_to<> () (36.0, 36); + static_assert ( !bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/comparisons/transparent.pass.cpp b/test/std/utilities/function.objects/comparisons/transparent.pass.cpp new file mode 100644 index 0000000000000..41ce4bcae65fd --- /dev/null +++ b/test/std/utilities/function.objects/comparisons/transparent.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 <functional> +#include <string> + +template <class _Tp> +struct is_transparent +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::is_transparent* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + + +int main () { +#if _LIBCPP_STD_VER > 11 + + static_assert ( !is_transparent<std::less<int>>::value, "" ); + static_assert ( !is_transparent<std::less<std::string>>::value, "" ); + static_assert ( is_transparent<std::less<void>>::value, "" ); + static_assert ( is_transparent<std::less<>>::value, "" ); + + static_assert ( !is_transparent<std::less_equal<int>>::value, "" ); + static_assert ( !is_transparent<std::less_equal<std::string>>::value, "" ); + static_assert ( is_transparent<std::less_equal<void>>::value, "" ); + static_assert ( is_transparent<std::less_equal<>>::value, "" ); + + static_assert ( !is_transparent<std::equal_to<int>>::value, "" ); + static_assert ( !is_transparent<std::equal_to<std::string>>::value, "" ); + static_assert ( is_transparent<std::equal_to<void>>::value, "" ); + static_assert ( is_transparent<std::equal_to<>>::value, "" ); + + static_assert ( !is_transparent<std::not_equal_to<int>>::value, "" ); + static_assert ( !is_transparent<std::not_equal_to<std::string>>::value, "" ); + static_assert ( is_transparent<std::not_equal_to<void>>::value, "" ); + static_assert ( is_transparent<std::not_equal_to<>>::value, "" ); + + static_assert ( !is_transparent<std::greater<int>>::value, "" ); + static_assert ( !is_transparent<std::greater<std::string>>::value, "" ); + static_assert ( is_transparent<std::greater<void>>::value, "" ); + static_assert ( is_transparent<std::greater<>>::value, "" ); + + static_assert ( !is_transparent<std::greater_equal<int>>::value, "" ); + static_assert ( !is_transparent<std::greater_equal<std::string>>::value, "" ); + static_assert ( is_transparent<std::greater_equal<void>>::value, "" ); + static_assert ( is_transparent<std::greater_equal<>>::value, "" ); + +#endif + + return 0; + } diff --git a/test/std/utilities/function.objects/func.def/nothing_to_do.pass.cpp b/test/std/utilities/function.objects/func.def/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/function.objects/func.def/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp b/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp new file mode 100644 index 0000000000000..4b9cc76f7e4f6 --- /dev/null +++ b/test/std/utilities/function.objects/func.invoke/invoke.pass.cpp @@ -0,0 +1,268 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11, c++14 + +// <functional> + +// template <class F, class ...Args> +// result_of_t<F&&(Args&&...)> invoke(F&&, Args&&...); + +/// C++14 [func.def] 20.9.0 +/// (1) The following definitions apply to this Clause: +/// (2) A call signature is the name of a return type followed by a parenthesized +/// comma-separated list of zero or more argument types. +/// (3) A callable type is a function object type (20.9) or a pointer to member. +/// (4) A callable object is an object of a callable type. +/// (5) A call wrapper type is a type that holds a callable object and supports +/// a call operation that forwards to that object. +/// (6) A call wrapper is an object of a call wrapper type. +/// (7) A target object is the callable object held by a call wrapper. + +/// C++14 [func.require] 20.9.1 +/// +/// Define INVOKE (f, t1, t2, ..., tN) as follows: +/// (1.1) - (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of +/// type T or a reference to an object of type T or a reference to an object of a type derived from T; +/// (1.2) - ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is not one of +/// the types described in the previous item; +/// (1.3) - t1.*f when N == 1 and f is a pointer to member data of a class T and t1 is an object of type T or a +/// reference to an object of type T or a reference to an object of a type derived from T; +/// (1.4) - (*t1).*f when N == 1 and f is a pointer to member data of a class T and t1 is not one of the types +/// described in the previous item; +/// (1.5) - f(t1, t2, ..., tN) in all other cases. + +#include <functional> +#include <type_traits> +#include <cassert> + +struct NonCopyable { + NonCopyable() {} +private: + NonCopyable(NonCopyable const&) = delete; + NonCopyable& operator=(NonCopyable const&) = delete; +}; + +struct TestClass { + explicit TestClass(int x) : data(x) {} + + int& operator()(NonCopyable&&) & { return data; } + int const& operator()(NonCopyable&&) const & { return data; } + int volatile& operator()(NonCopyable&&) volatile & { return data; } + int const volatile& operator()(NonCopyable&&) const volatile & { return data; } + + int&& operator()(NonCopyable&&) && { return std::move(data); } + int const&& operator()(NonCopyable&&) const && { return std::move(data); } + int volatile&& operator()(NonCopyable&&) volatile && { return std::move(data); } + int const volatile&& operator()(NonCopyable&&) const volatile && { return std::move(data); } + + int data; +private: + TestClass(TestClass const&) = delete; + TestClass& operator=(TestClass const&) = delete; +}; + +struct DerivedFromTestClass : public TestClass { + explicit DerivedFromTestClass(int x) : TestClass(x) {} +}; + +int& foo(NonCopyable&&) { + static int data = 42; + return data; +} + +template <class Signature, class Expect, class Functor> +void test_b12(Functor&& f) { + // Create the callable object. + typedef Signature TestClass::*ClassFunc; + ClassFunc func_ptr = &TestClass::operator(); + + // Create the dummy arg. + NonCopyable arg; + + // Check that the deduced return type of invoke is what is expected. + typedef decltype( + std::invoke(func_ptr, std::forward<Functor>(f), std::move(arg)) + ) DeducedReturnType; + static_assert((std::is_same<DeducedReturnType, Expect>::value), ""); + + // Check that result_of_t matches Expect. + typedef typename std::result_of<ClassFunc&&(Functor&&, NonCopyable&&)>::type + ResultOfReturnType; + static_assert((std::is_same<ResultOfReturnType, Expect>::value), ""); + + // Run invoke and check the return value. + DeducedReturnType ret = + std::invoke(func_ptr, std::forward<Functor>(f), std::move(arg)); + assert(ret == 42); +} + +template <class Expect, class Functor> +void test_b34(Functor&& f) { + // Create the callable object. + typedef int TestClass::*ClassFunc; + ClassFunc func_ptr = &TestClass::data; + + // Check that the deduced return type of invoke is what is expected. + typedef decltype( + std::invoke(func_ptr, std::forward<Functor>(f)) + ) DeducedReturnType; + static_assert((std::is_same<DeducedReturnType, Expect>::value), ""); + + // Check that result_of_t matches Expect. + typedef typename std::result_of<ClassFunc&&(Functor&&)>::type + ResultOfReturnType; + static_assert((std::is_same<ResultOfReturnType, Expect>::value), ""); + + // Run invoke and check the return value. + DeducedReturnType ret = + std::invoke(func_ptr, std::forward<Functor>(f)); + assert(ret == 42); +} + +template <class Expect, class Functor> +void test_b5(Functor&& f) { + NonCopyable arg; + + // Check that the deduced return type of invoke is what is expected. + typedef decltype( + std::invoke(std::forward<Functor>(f), std::move(arg)) + ) DeducedReturnType; + static_assert((std::is_same<DeducedReturnType, Expect>::value), ""); + + // Check that result_of_t matches Expect. + typedef typename std::result_of<Functor&&(NonCopyable&&)>::type + ResultOfReturnType; + static_assert((std::is_same<ResultOfReturnType, Expect>::value), ""); + + // Run invoke and check the return value. + DeducedReturnType ret = std::invoke(std::forward<Functor>(f), std::move(arg)); + assert(ret == 42); +} + +void bullet_one_two_tests() { + { + TestClass cl(42); + test_b12<int&(NonCopyable&&) &, int&>(cl); + test_b12<int const&(NonCopyable&&) const &, int const&>(cl); + test_b12<int volatile&(NonCopyable&&) volatile &, int volatile&>(cl); + test_b12<int const volatile&(NonCopyable&&) const volatile &, int const volatile&>(cl); + + test_b12<int&&(NonCopyable&&) &&, int&&>(std::move(cl)); + test_b12<int const&&(NonCopyable&&) const &&, int const&&>(std::move(cl)); + test_b12<int volatile&&(NonCopyable&&) volatile &&, int volatile&&>(std::move(cl)); + test_b12<int const volatile&&(NonCopyable&&) const volatile &&, int const volatile&&>(std::move(cl)); + } + { + DerivedFromTestClass cl(42); + test_b12<int&(NonCopyable&&) &, int&>(cl); + test_b12<int const&(NonCopyable&&) const &, int const&>(cl); + test_b12<int volatile&(NonCopyable&&) volatile &, int volatile&>(cl); + test_b12<int const volatile&(NonCopyable&&) const volatile &, int const volatile&>(cl); + + test_b12<int&&(NonCopyable&&) &&, int&&>(std::move(cl)); + test_b12<int const&&(NonCopyable&&) const &&, int const&&>(std::move(cl)); + test_b12<int volatile&&(NonCopyable&&) volatile &&, int volatile&&>(std::move(cl)); + test_b12<int const volatile&&(NonCopyable&&) const volatile &&, int const volatile&&>(std::move(cl)); + } + { + TestClass cl_obj(42); + TestClass *cl = &cl_obj; + test_b12<int&(NonCopyable&&) &, int&>(cl); + test_b12<int const&(NonCopyable&&) const &, int const&>(cl); + test_b12<int volatile&(NonCopyable&&) volatile &, int volatile&>(cl); + test_b12<int const volatile&(NonCopyable&&) const volatile &, int const volatile&>(cl); + } + { + DerivedFromTestClass cl_obj(42); + DerivedFromTestClass *cl = &cl_obj; + test_b12<int&(NonCopyable&&) &, int&>(cl); + test_b12<int const&(NonCopyable&&) const &, int const&>(cl); + test_b12<int volatile&(NonCopyable&&) volatile &, int volatile&>(cl); + test_b12<int const volatile&(NonCopyable&&) const volatile &, int const volatile&>(cl); + } +} + +void bullet_three_four_tests() { + { + typedef TestClass Fn; + Fn cl(42); + test_b34<int&>(cl); + test_b34<int const&>(static_cast<Fn const&>(cl)); + test_b34<int volatile&>(static_cast<Fn volatile&>(cl)); + test_b34<int const volatile&>(static_cast<Fn const volatile &>(cl)); + + test_b34<int&&>(static_cast<Fn &&>(cl)); + test_b34<int const&&>(static_cast<Fn const&&>(cl)); + test_b34<int volatile&&>(static_cast<Fn volatile&&>(cl)); + test_b34<int const volatile&&>(static_cast<Fn const volatile&&>(cl)); + } + { + typedef DerivedFromTestClass Fn; + Fn cl(42); + test_b34<int&>(cl); + test_b34<int const&>(static_cast<Fn const&>(cl)); + test_b34<int volatile&>(static_cast<Fn volatile&>(cl)); + test_b34<int const volatile&>(static_cast<Fn const volatile &>(cl)); + + test_b34<int&&>(static_cast<Fn &&>(cl)); + test_b34<int const&&>(static_cast<Fn const&&>(cl)); + test_b34<int volatile&&>(static_cast<Fn volatile&&>(cl)); + test_b34<int const volatile&&>(static_cast<Fn const volatile&&>(cl)); + } + { + typedef TestClass Fn; + Fn cl_obj(42); + Fn* cl = &cl_obj; + test_b34<int&>(cl); + test_b34<int const&>(static_cast<Fn const*>(cl)); + test_b34<int volatile&>(static_cast<Fn volatile*>(cl)); + test_b34<int const volatile&>(static_cast<Fn const volatile *>(cl)); + } + { + typedef DerivedFromTestClass Fn; + Fn cl_obj(42); + Fn* cl = &cl_obj; + test_b34<int&>(cl); + test_b34<int const&>(static_cast<Fn const*>(cl)); + test_b34<int volatile&>(static_cast<Fn volatile*>(cl)); + test_b34<int const volatile&>(static_cast<Fn const volatile *>(cl)); + } +} + +void bullet_five_tests() { + using FooType = int&(NonCopyable&&); + { + FooType& fn = foo; + test_b5<int &>(fn); + } + { + FooType* fn = foo; + test_b5<int &>(fn); + } + { + typedef TestClass Fn; + Fn cl(42); + test_b5<int&>(cl); + test_b5<int const&>(static_cast<Fn const&>(cl)); + test_b5<int volatile&>(static_cast<Fn volatile&>(cl)); + test_b5<int const volatile&>(static_cast<Fn const volatile &>(cl)); + + test_b5<int&&>(static_cast<Fn &&>(cl)); + test_b5<int const&&>(static_cast<Fn const&&>(cl)); + test_b5<int volatile&&>(static_cast<Fn volatile&&>(cl)); + test_b5<int const volatile&&>(static_cast<Fn const volatile&&>(cl)); + } +} + +int main() { + bullet_one_two_tests(); + bullet_three_four_tests(); + bullet_five_tests(); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_data.fail.cpp b/test/std/utilities/function.objects/func.memfn/member_data.fail.cpp new file mode 100644 index 0000000000000..5e748c93b9e4d --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_data.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T> unspecified mem_fn(R T::* pm); + +#include <functional> +#include <cassert> + +struct A +{ + double data_; +}; + +template <class F> +void +test(F f) +{ + { + A a; + f(a) = 5; + assert(a.data_ == 5); + A* ap = &a; + f(ap) = 6; + assert(a.data_ == 6); + const A* cap = ap; + assert(f(cap) == f(ap)); + f(cap) = 7; + } +} + +int main() +{ + test(std::mem_fn(&A::data_)); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_data.pass.cpp b/test/std/utilities/function.objects/func.memfn/member_data.pass.cpp new file mode 100644 index 0000000000000..dff211c605730 --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_data.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T> unspecified mem_fn(R T::* pm); + +#include <functional> +#include <cassert> + +struct A +{ + double data_; +}; + +template <class F> +void +test(F f) +{ + { + A a; + f(a) = 5; + assert(a.data_ == 5); + A* ap = &a; + f(ap) = 6; + assert(a.data_ == 6); + const A* cap = ap; + assert(f(cap) == f(ap)); + const F& cf = f; + assert(cf(ap) == f(ap)); + } +} + +int main() +{ + test(std::mem_fn(&A::data_)); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_function.pass.cpp b/test/std/utilities/function.objects/func.memfn/member_function.pass.cpp new file mode 100644 index 0000000000000..4096bd8144215 --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_function.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...)); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() {return 'a';} + char test1(int) {return 'b';} + char test2(int, double) {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_function_const.pass.cpp b/test/std/utilities/function.objects/func.memfn/member_function_const.pass.cpp new file mode 100644 index 0000000000000..be22443e95420 --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_function_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) const); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() const {return 'a';} + char test1(int) const {return 'b';} + char test2(int, double) const {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + const A* cap = &a; + assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + const A* cap = &a; + assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + const A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp b/test/std/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp new file mode 100644 index 0000000000000..329ac16a86db2 --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) const volatile); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() const volatile {return 'a';} + char test1(int) const volatile {return 'b';} + char test2(int, double) const volatile {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + const volatile A* cap = &a; + assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + const volatile A* cap = &a; + assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + const volatile A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/test/std/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp b/test/std/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp new file mode 100644 index 0000000000000..743ded9944aad --- /dev/null +++ b/test/std/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, class T, CopyConstructible... Args> +// unspecified mem_fn(R (T::* pm)(Args...) volatile); + +#include <functional> +#include <cassert> + +struct A +{ + char test0() volatile {return 'a';} + char test1(int) volatile {return 'b';} + char test2(int, double) volatile {return 'c';} +}; + +template <class F> +void +test0(F f) +{ + { + A a; + assert(f(a) == 'a'); + A* ap = &a; + assert(f(ap) == 'a'); + volatile A* cap = &a; + assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); + } +} + +template <class F> +void +test1(F f) +{ + { + A a; + assert(f(a, 1) == 'b'); + A* ap = &a; + assert(f(ap, 2) == 'b'); + volatile A* cap = &a; + assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); + } +} + +template <class F> +void +test2(F f) +{ + { + A a; + assert(f(a, 1, 2) == 'c'); + A* ap = &a; + assert(f(ap, 2, 3.5) == 'c'); + volatile A* cap = &a; + assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); + } +} + +int main() +{ + test0(std::mem_fn(&A::test0)); + test1(std::mem_fn(&A::test1)); + test2(std::mem_fn(&A::test2)); +} diff --git a/test/std/utilities/function.objects/func.require/binary_function.pass.cpp b/test/std/utilities/function.objects/func.require/binary_function.pass.cpp new file mode 100644 index 0000000000000..fa7afb2e7b9c0 --- /dev/null +++ b/test/std/utilities/function.objects/func.require/binary_function.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// binary_function + +#include <functional> +#include <type_traits> + +int main() +{ + typedef std::binary_function<int, short, bool> bf; + static_assert((std::is_same<bf::first_argument_type, int>::value), ""); + static_assert((std::is_same<bf::second_argument_type, short>::value), ""); + static_assert((std::is_same<bf::result_type, bool>::value), ""); +} diff --git a/test/std/utilities/function.objects/func.require/invoke.pass.cpp b/test/std/utilities/function.objects/func.require/invoke.pass.cpp new file mode 100644 index 0000000000000..25681630a80c3 --- /dev/null +++ b/test/std/utilities/function.objects/func.require/invoke.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// [func.require] + +// INVOKE +#if __cplusplus < 201103L +int main () {} // no __invoke in C++03 +#else + +#include <type_traits> + +template <typename T, int N> +struct Array +{ + typedef T type[N]; +}; + +struct Type +{ + Array<char, 1>::type& f1(); + Array<char, 2>::type& f2() const; + + Array<char, 1>::type& g1() &; + Array<char, 2>::type& g2() const &; +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Array<char, 3>::type& g3() &&; + Array<char, 4>::type& g4() const &&; +#endif +}; + +int main() +{ + static_assert(sizeof(std::__invoke(&Type::f1, std::declval<Type >())) == 1, ""); + static_assert(sizeof(std::__invoke(&Type::f2, std::declval<Type const >())) == 2, ""); + + static_assert(sizeof(std::__invoke(&Type::g1, std::declval<Type &>())) == 1, ""); + static_assert(sizeof(std::__invoke(&Type::g2, std::declval<Type const &>())) == 2, ""); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert(sizeof(std::__invoke(&Type::g3, std::declval<Type &&>())) == 3, ""); + static_assert(sizeof(std::__invoke(&Type::g4, std::declval<Type const&&>())) == 4, ""); +#endif +} +#endif diff --git a/test/std/utilities/function.objects/func.require/unary_function.pass.cpp b/test/std/utilities/function.objects/func.require/unary_function.pass.cpp new file mode 100644 index 0000000000000..f14b2d3a2ce5f --- /dev/null +++ b/test/std/utilities/function.objects/func.require/unary_function.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// unary_function + +#include <functional> +#include <type_traits> + +int main() +{ + typedef std::unary_function<int, bool> uf; + static_assert((std::is_same<uf::argument_type, int>::value), ""); + static_assert((std::is_same<uf::result_type, bool>::value), ""); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp new file mode 100644 index 0000000000000..357a3b48eae20 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/bad_function_call.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// class bad_function_call +// : public exception +// { +// public: +// // 20.7.16.1.1, constructor: +// bad_function_call(); +// }; + +#include <functional> +#include <type_traits> + +int main() +{ + static_assert((std::is_base_of<std::exception, std::bad_function_call>::value), ""); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp new file mode 100644 index 0000000000000..f5ab9487532f4 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/func.wrap.badcall.const/bad_function_call_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// Class bad_function_call + +// bad_function_call(); + +#include <functional> +#include <type_traits> + +int main() +{ + std::bad_function_call ex; +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp new file mode 100644 index 0000000000000..58192c928d585 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); + + +#include <functional> +#include <cstdlib> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + explicit A(int j) + { + ++count; + data_[0] = j; + } + + A(const A& a) + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = a.data_[i]; + } + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int id() const {return data_[0];} +}; + +int A::count = 0; + +int g(int) {return 0;} +int h(int) {return 1;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = A(2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target<A>()->id() == 1); + assert(f2.target<A>()->id() == 2); + swap(f1, f2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target<A>()->id() == 2); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = g; + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + swap(f1, f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = A(1); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + swap(f1, f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = h; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target<int(*)(int)>() == g); + assert(*f2.target<int(*)(int)>() == h); + swap(f1, f2); + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target<int(*)(int)>() == h); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp new file mode 100644 index 0000000000000..829763f79d822 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.cap/operator_bool.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// explicit operator bool() const + +#include <functional> +#include <cassert> + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f; + assert(!f); + f = g; + assert(f); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp new file mode 100644 index 0000000000000..cd86e4cbf8ebe --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(nullptr_t); + +#include <functional> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = (int (*)(int))0; + assert(!f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f = &A::foo; + assert(f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int (A::*)(int) const>() != 0); + } + { + std::function<void(int)> f(&g); + assert(f); + assert(f.target<int(*)(int)>() != 0); + f(1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp new file mode 100644 index 0000000000000..11716e7946b04 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class F> +// requires CopyConstructible<F> && Callable<F, ArgTypes..> +// && Convertible<Callable<F, ArgTypes...>::result_type +// operator=(F f); + +#include <functional> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f; + f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f; + f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f; + f = (int (*)(int))0; + assert(!f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + } + { + std::function<int(const A*, int)> f; + f = &A::foo; + assert(f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int (A::*)(int) const>() != 0); + } + { + std::function<void(int)> f; + f = &g; + assert(f); + assert(f.target<int(*)(int)>() != 0); + f(1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp new file mode 100644 index 0000000000000..c8f4178a26bdd --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_incomplete.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class F> function(F); + +// Allow incomplete argument types in the __is_callable check + +#include <functional> + +struct X{ + typedef std::function<void(X&)> callback_type; + virtual ~X() {} +private: + callback_type _cb; +}; + +int main() +{ +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp new file mode 100644 index 0000000000000..f97e34d3f2cbe --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&); + +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::function<int(int)> f(std::allocator_arg, bare_allocator<int>()); + assert(!f); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp new file mode 100644 index 0000000000000..352ecfc602be4 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class F, class A> function(allocator_arg_t, const A&, F); + +#include <functional> +#include <cassert> + +#include "min_allocator.h" +#include "test_allocator.h" +#include "count_new.hpp" +#include "../function_types.h" + +class DummyClass {}; + +template <class FuncType, class AllocType> +void test_FunctionObject(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + FunctionObject target; + assert(FunctionObject::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function<FuncType> f2(std::allocator_arg, alloc, target); + assert(FunctionObject::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.template target<FunctionObject>()); + assert(f2.template target<FuncType>() == 0); + assert(f2.template target<FuncType*>() == 0); + } + assert(FunctionObject::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + + +template <class FuncType, class AllocType> +void test_FreeFunction(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + FuncType* target = &FreeFunction; + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function<FuncType> f2(std::allocator_arg, alloc, target); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target<FuncType*>()); + assert(*f2.template target<FuncType*>() == target); + assert(f2.template target<FuncType>() == 0); + assert(f2.template target<DummyClass>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template <class TargetType, class FuncType, class AllocType> +void test_MemFunClass(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + TargetType target = &MemFunClass::foo; + assert(globalMemCounter.checkOutstandingNewEq(0)); + std::function<FuncType> f2(std::allocator_arg, alloc, target); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target<TargetType>()); + assert(*f2.template target<TargetType>() == target); + assert(f2.template target<FuncType*>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template <class Alloc> +void test_for_alloc(Alloc& alloc) { + test_FunctionObject<int()>(alloc); + test_FunctionObject<int(int)>(alloc); + test_FunctionObject<int(int, int)>(alloc); + test_FunctionObject<int(int, int, int)>(alloc); + + test_FreeFunction<int()>(alloc); + test_FreeFunction<int(int)>(alloc); + test_FreeFunction<int(int, int)>(alloc); + test_FreeFunction<int(int, int, int)>(alloc); + + test_MemFunClass<int(MemFunClass::*)() const, int(MemFunClass&)>(alloc); + test_MemFunClass<int(MemFunClass::*)(int) const, int(MemFunClass&, int)>(alloc); + test_MemFunClass<int(MemFunClass::*)(int, int) const, int(MemFunClass&, int, int)>(alloc); +} + +int main() +{ + { + bare_allocator<DummyClass> bare_alloc; + test_for_alloc(bare_alloc); + } + { + non_default_test_allocator<DummyClass> non_default_alloc(42); + test_for_alloc(non_default_alloc); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp new file mode 100644 index 0000000000000..371eb98de1a9b --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, const function&); + + +#include <functional> +#include <cassert> + +#include "min_allocator.h" +#include "test_allocator.h" +#include "count_new.hpp" +#include "../function_types.h" + +class DummyClass {}; + +template <class FuncType, class AllocType> +void test_FunctionObject(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from FunctionObject. + std::function<FuncType> f = FunctionObject(); + assert(FunctionObject::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.template target<FunctionObject>()); + assert(f.template target<FuncType>() == 0); + assert(f.template target<FuncType*>() == 0); + // Copy function with allocator + std::function<FuncType> f2(std::allocator_arg, alloc, f); + assert(FunctionObject::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.template target<FunctionObject>()); + assert(f2.template target<FuncType>() == 0); + assert(f2.template target<FuncType*>() == 0); + } + assert(FunctionObject::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template <class FuncType, class AllocType> +void test_FreeFunction(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from function pointer. + FuncType* target = &FreeFunction; + std::function<FuncType> f = target; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.template target<FuncType*>()); + assert(*f.template target<FuncType*>() == target); + assert(f.template target<FuncType>() == 0); + // Copy function with allocator + std::function<FuncType> f2(std::allocator_arg, alloc, f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target<FuncType*>()); + assert(*f2.template target<FuncType*>() == target); + assert(f2.template target<FuncType>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template <class TargetType, class FuncType, class AllocType> +void test_MemFunClass(AllocType& alloc) +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + // Construct function from function pointer. + TargetType target = &MemFunClass::foo; + std::function<FuncType> f = target; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.template target<TargetType>()); + assert(*f.template target<TargetType>() == target); + assert(f.template target<FuncType*>() == 0); + // Copy function with allocator + std::function<FuncType> f2(std::allocator_arg, alloc, f); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.template target<TargetType>()); + assert(*f2.template target<TargetType>() == target); + assert(f2.template target<FuncType*>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); +} + +template <class Alloc> +void test_for_alloc(Alloc& alloc) +{ + // Large FunctionObject -- Allocation should occur + test_FunctionObject<int()>(alloc); + test_FunctionObject<int(int)>(alloc); + test_FunctionObject<int(int, int)>(alloc); + test_FunctionObject<int(int, int, int)>(alloc); + // Free function -- No allocation should occur + test_FreeFunction<int()>(alloc); + test_FreeFunction<int(int)>(alloc); + test_FreeFunction<int(int, int)>(alloc); + test_FreeFunction<int(int, int, int)>(alloc); + // Member function -- No allocation should occur. + test_MemFunClass<int(MemFunClass::*)() const, int(MemFunClass&)>(alloc); + test_MemFunClass<int(MemFunClass::*)(int) const, int(MemFunClass&, int)>(alloc); + test_MemFunClass<int(MemFunClass::*)(int, int) const, int(MemFunClass&, int, int)>(alloc); +} + +int main() +{ + { + bare_allocator<DummyClass> alloc; + test_for_alloc(alloc); + } + { + non_default_test_allocator<DummyClass> alloc(42); + test_for_alloc(alloc); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp new file mode 100644 index 0000000000000..2350f92f0f893 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, nullptr_t); + +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + std::function<int(int)> f(std::allocator_arg, bare_allocator<int>(), nullptr); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp new file mode 100644 index 0000000000000..aa6b743b5236b --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, function&&); + +#include <functional> +#include <cassert> + +#include "min_allocator.h" +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2(std::allocator_arg, bare_allocator<A>(), std::move(f)); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(f.target<int(*)(int)>() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp new file mode 100644 index 0000000000000..f603da9dd1319 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(const function& f); + +#include <functional> +#include <cstdlib> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = f; + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } + { + std::function<int(int)> f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(!f); + std::function<long(int)> g = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(g.target<long(*)(int)>() == 0); + assert(g.target<A>() == 0); + assert(!g); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2 = std::move(f); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(f.target<int(*)(int)>() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp new file mode 100644 index 0000000000000..c91eaa2d56744 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(const function& f); + +#include <functional> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target<int(*)(int)>()); + assert(f2.target<A>() == 0); + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + std::function<int(int)> f2; + f2 = f; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<A>() == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + std::function<int(int)> f2; + f2 = std::move(f); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f2.target<A>()); + assert(f2.target<int(*)(int)>() == 0); + assert(f.target<A>() == 0); + assert(f.target<int(*)(int)>() == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp new file mode 100644 index 0000000000000..83d61b6b2d89e --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/default.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// explicit function(); + +#include <functional> +#include <cassert> + +int main() +{ + std::function<int(int)> f; + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp new file mode 100644 index 0000000000000..7099c45fab81f --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/no-variadics.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R()> + +// template<class F> function(F); + +#define _LIBCPP_HAS_NO_VARIADICS +#include <functional> +#include <cassert> + +int main() +{ + std::function<void()> f(static_cast<void(*)()>(0)); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp new file mode 100644 index 0000000000000..f0d6402d185e4 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function(nullptr_t); + +#include <functional> +#include <cassert> + +int main() +{ + std::function<int(int)> f(nullptr); + assert(!f); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp new file mode 100644 index 0000000000000..9b2482fb9d544 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// function& operator=(nullptr_t); + +#include <functional> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f.target<A>()); + f = nullptr; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<A>() == 0); + } + { + std::function<int(int)> f = g; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + f = nullptr; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(f.target<int(*)(int)>() == 0); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp new file mode 100644 index 0000000000000..6dcd2857452cc --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +// member data pointer: cv qualifiers should transfer from argument to return type + +struct A_int_1 +{ + A_int_1() : data_(5) {} + + int data_; +}; + +void +test_int_1() +{ + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + A_int_1 a; + std::function<int& (const A_int_1*)> r2(fp); + const A_int_1* ap = &a; + assert(r2(ap) == 6); + r2(ap) = 7; + assert(r2(ap) == 7); + } +} + +int main() +{ + test_int_1(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp new file mode 100644 index 0000000000000..31b80c3323c10 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.pass.cpp @@ -0,0 +1,335 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {++count;} +}; + +void +test_void_1() +{ + int save_count = count; + // function + { + std::function<void (int)> r1(f_void_1); + int i = 2; + r1(i); + assert(count == save_count+2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::function<void (int)> r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::function<void (int)> r1(a0); + int i = 4; + r1(i); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::function<void (A_void_1)> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + std::function<void (A_void_1*)> r2 = fp; + r2(ap); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::function<void (A_void_1)> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + std::function<void (A_void_1*)> r2(fp); + A_void_1* ap = &a; + r2(ap); + assert(count == save_count+1); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + // function + { + std::function<int (int)> r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::function<int (int)> r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::function<int (int)> r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::function<int (A_int_1)> r1(fp); + A_int_1 a; + assert(r1(a) == 3); + std::function<int (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 3); + } + // const member function pointer + { + int (A_int_1::*fp)() const = &A_int_1::mem2; + std::function<int (A_int_1)> r1(fp); + A_int_1 a; + assert(r1(a) == 4); + std::function<int (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 4); + } + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::function<int& (A_int_1&)> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + std::function<int& (A_int_1*)> r2(fp); + A_int_1* ap = &a; + assert(r2(ap) == 6); + r2(ap) = 7; + assert(r2(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + int save_count = count; + // function + { + std::function<void (int, int)> r1(f_void_2); + int i = 2; + int j = 3; + r1(i, j); + assert(count == save_count+5); + save_count = count; + } + // function pointer + { + void (*fp)(int, int) = f_void_2; + std::function<void (int, int)> r1(fp); + int i = 3; + int j = 4; + r1(i, j); + assert(count == save_count+7); + save_count = count; + } + // functor + { + A_void_2 a0; + std::function<void (int, int)> r1(a0); + int i = 4; + int j = 5; + r1(i, j); + assert(count == save_count+9); + save_count = count; + } + // member function pointer + { + void (A_void_2::*fp)(int) = &A_void_2::mem1; + std::function<void (A_void_2, int)> r1(fp); + A_void_2 a; + int i = 3; + r1(a, i); + assert(count == save_count+3); + save_count = count; + std::function<void (A_void_2*, int)> r2(fp); + A_void_2* ap = &a; + r2(ap, i); + assert(count == save_count+3); + save_count = count; + } + // const member function pointer + { + void (A_void_2::*fp)(int) const = &A_void_2::mem2; + std::function<void (A_void_2, int)> r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + std::function<void (A_void_2*, int)> r2(fp); + A_void_2* ap = &a; + r2(ap, i); + assert(count == save_count+4); + save_count = count; + } +} + +// 2 arg, return int + +int f_int_2(int i, int j) +{ + return i+j; +} + +struct A_int_2 +{ + int operator()(int i, int j) + { + return i+j; + } + + int mem1(int i) {return i+1;} + int mem2(int i) const {return i+2;} +}; + +void +testint_2() +{ + // function + { + std::function<int (int, int)> r1(f_int_2); + int i = 2; + int j = 3; + assert(r1(i, j) == i+j); + } + // function pointer + { + int (*fp)(int, int) = f_int_2; + std::function<int (int, int)> r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::function<int (int, int)> r1(a0); + int i = 4; + int j = 5; + assert(r1(i, j) == i+j); + } + // member function pointer + { + int(A_int_2::*fp)(int) = &A_int_2::mem1; + std::function<int (A_int_2, int)> r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + std::function<int (A_int_2*, int)> r2(fp); + A_int_2* ap = &a; + assert(r2(ap, i) == i+1); + } + // const member function pointer + { + int (A_int_2::*fp)(int) const = &A_int_2::mem2; + std::function<int (A_int_2, int)> r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + std::function<int (A_int_2*, int)> r2(fp); + A_int_2* ap = &a; + assert(r2(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp new file mode 100644 index 0000000000000..67b4ec22da8c7 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_int_0.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <cassert> + +// 0 args, return int + +int count = 0; + +int f_int_0() +{ + return 3; +} + +struct A_int_0 +{ + int operator()() {return 4;} +}; + +void +test_int_0() +{ + // function + { + std::function<int ()> r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::function<int ()> r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::function<int ()> r1(a0); + assert(r1() == 4); + } +} + +int main() +{ + test_int_0(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp new file mode 100644 index 0000000000000..c0a14fd96fcbc --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_no_variadics.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R()> + +// Test that we properly return both values and void for all non-variadic +// overloads of function::operator()(...) + +#define _LIBCPP_HAS_NO_VARIADICS +#include <functional> +#include <cassert> + +int foo0() { return 42; } +int foo1(int) { return 42; } +int foo2(int, int) { return 42; } +int foo3(int, int, int) { return 42; } + +int main() +{ + { + std::function<int()> f(&foo0); + assert(f() == 42); + } + { + std::function<int(int)> f(&foo1); + assert(f(1) == 42); + } + { + std::function<int(int, int)> f(&foo2); + assert(f(1, 1) == 42); + } + { + std::function<int(int, int, int)> f(&foo3); + assert(f(1, 1, 1) == 42); + } + { + std::function<void()> f(&foo0); + f(); + } + { + std::function<void(int)> f(&foo1); + f(1); + } + { + std::function<void(int, int)> f(&foo2); + f(1, 1); + } + { + std::function<void(int, int, int)> f(&foo3); + f(1, 1, 1); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp new file mode 100644 index 0000000000000..a820cb1b8f38e --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke_void_0.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// R operator()(ArgTypes... args) const + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +// 0 args, return void + +int count = 0; + +void f_void_0() +{ + ++count; +} + +struct A_void_0 +{ + void operator()() {++count;} +}; + +void +test_void_0() +{ + int save_count = count; + // function + { + std::function<void ()> r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::function<void ()> r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::function<void ()> r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp new file mode 100644 index 0000000000000..e9ecfa5539ce5 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/assign_F_alloc.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<class F, class A> void assign(F&&, const A&); + +#include <functional> +#include <cassert> + +#include "test_allocator.h" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int main() +{ + { + std::function<int(int)> f; + f.assign(A(), test_allocator<A>()); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp new file mode 100644 index 0000000000000..f94e689b2a6bc --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// void swap(function& other); + +#include <functional> +#include <cassert> + +#include "count_new.hpp" + +class A +{ + int data_[10]; +public: + static int count; + + explicit A(int j) + { + ++count; + data_[0] = j; + } + + A(const A& a) + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = a.data_[i]; + } + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int id() const {return data_[0];} +}; + +int A::count = 0; + +int g(int) {return 0;} +int h(int) {return 1;} + +int main() +{ + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = A(2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target<A>()->id() == 1); + assert(f2.target<A>()->id() == 2); + f1.swap(f2); + assert(A::count == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); + assert(f1.target<A>()->id() == 2); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = A(1); + std::function<int(int)> f2 = g; + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + f1.swap(f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = A(1); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(*f1.target<int(*)(int)>() == g); + assert(f2.target<A>()->id() == 1); + f1.swap(f2); + assert(A::count == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(f1.target<A>()->id() == 1); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { + std::function<int(int)> f1 = g; + std::function<int(int)> f2 = h; + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target<int(*)(int)>() == g); + assert(*f2.target<int(*)(int)>() == h); + f1.swap(f2); + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(*f1.target<int(*)(int)>() == h); + assert(*f2.target<int(*)(int)>() == g); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp new file mode 100644 index 0000000000000..5bca0968702c0 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.nullptr/operator_==.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator==(const function<R(ArgTypes...)>&, nullptr_t); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator==(nullptr_t, const function<R(ArgTypes...)>&); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator!=(const function<R(ArgTypes...)>&, nullptr_t); +// +// template <MoveConstructible R, MoveConstructible ... ArgTypes> +// bool operator!=(nullptr_t, const function<R(ArgTypes...)>&); + +#include <functional> +#include <cassert> + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f; + assert(f == nullptr); + assert(nullptr == f); + f = g; + assert(f != nullptr); + assert(nullptr != f); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp new file mode 100644 index 0000000000000..53476a2747357 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// template<typename T> +// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> +// T* +// target(); +// template<typename T> +// requires Callable<T, ArgTypes...> && Convertible<Callable<T, ArgTypes...>::result_type, R> +// const T* +// target() const; + +#include <functional> +#include <new> +#include <cstdlib> +#include <cassert> + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f = A(); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + { + std::function<int(int)> f = g; + assert(A::count == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(A::count == 0); + { + const std::function<int(int)> f = A(); + assert(A::count == 1); + assert(f.target<A>()); + assert(f.target<int(*)(int)>() == 0); + } + assert(A::count == 0); + { + const std::function<int(int)> f = g; + assert(A::count == 0); + assert(f.target<int(*)(int)>()); + assert(f.target<A>() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp new file mode 100644 index 0000000000000..7605e3bf666e8 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.targ/target_type.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// class function<R(ArgTypes...)> + +// const std::type_info& target_type() const; + +#include <functional> +#include <typeinfo> +#include <cassert> + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } + + int foo(int) const {return 1;} +}; + +int A::count = 0; + +int g(int) {return 0;} + +int main() +{ + { + std::function<int(int)> f = A(); + assert(f.target_type() == typeid(A)); + } + { + std::function<int(int)> f; + assert(f.target_type() == typeid(void)); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h b/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h new file mode 100644 index 0000000000000..55eb80f43ffe3 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h @@ -0,0 +1,57 @@ +#ifndef FUNCTION_TYPES_H +#define FUNCTION_TYPES_H + + +class FunctionObject +{ + int data_[10]; // dummy variable to prevent small object optimization in + // std::function +public: + static int count; + + FunctionObject() { + ++count; + for (int i = 0; i < 10; ++i) data_[i] = i; + } + + FunctionObject(const FunctionObject&) {++count;} + ~FunctionObject() {--count; ((void)data_); } + + int operator()() const { return 42; } + int operator()(int i) const { return i; } + int operator()(int i, int) const { return i; } + int operator()(int i, int, int) const { return i; } +}; + +int FunctionObject::count = 0; + +class MemFunClass +{ + int data_[10]; // dummy variable to prevent small object optimization in + // std::function +public: + static int count; + + MemFunClass() { + ++count; + for (int i = 0; i < 10; ++i) data_[i] = 0; + } + + MemFunClass(const MemFunClass&) {++count; ((void)data_); } + + ~MemFunClass() {--count;} + + int foo() const { return 42; } + int foo(int i) const { return i; } + int foo(int i, int) const { return i; } + int foo(int i, int, int) const { return i; } +}; + +int MemFunClass::count = 0; + +int FreeFunction() { return 42; } +int FreeFunction(int i) {return i;} +int FreeFunction(int i, int) { return i; } +int FreeFunction(int i, int, int) { return i; } + +#endif // FUNCTION_TYPES_H diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp new file mode 100644 index 0000000000000..eb4eac65cd2cb --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template<Returnable R, CopyConstructible... ArgTypes> +// class function<R(ArgTypes...)> { +// public: +// typedef R result_type; +// typedef T1 argument_type; // iff sizeof...(ArgTypes) == 1 and +// // the type in ArgTypes is T1 +// typedef T1 first_argument_type; // iff sizeof...(ArgTypes) == 2 and +// // ArgTypes contains T1 and T2 +// typedef T2 second_argument_type; // iff sizeof...(ArgTypes) == 2 and +// // ArgTypes contains T1 and T2 +// ... +// }; + +#include <functional> +#include <type_traits> + + +template <typename T> +class has_argument_type +{ + typedef char yes; + typedef long no; + + template <typename C> static yes check( typename C::argument_type * ); + template <typename C> static no check(...); +public: + enum { value = sizeof(check<T>(0)) == sizeof(yes) }; +}; + +template <typename T> +class has_first_argument_type +{ + typedef char yes; + typedef long no; + + template <typename C> static yes check( typename C::first_argument_type * ); + template <typename C> static no check(...); +public: + enum { value = sizeof(check<T>(0)) == sizeof(yes) }; +}; + + +template <typename T> +class has_second_argument_type +{ + typedef char yes; + typedef long no; + + template <typename C> static yes check( typename C::second_argument_type *); + template <typename C> static no check(...); +public: + enum { value = sizeof(check<T>(0)) == sizeof(yes) }; +}; + +template <class F, class return_type> +void test_nullary_function () +{ + static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); + static_assert((!has_argument_type<F>::value), "" ); + static_assert((!has_first_argument_type<F>::value), "" ); + static_assert((!has_second_argument_type<F>::value), "" ); +} + +template <class F, class return_type, class arg_type> +void test_unary_function () +{ + static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); + static_assert((std::is_same<typename F::argument_type, arg_type>::value), "" ); + static_assert((!has_first_argument_type<F>::value), "" ); + static_assert((!has_second_argument_type<F>::value), "" ); +} + +template <class F, class return_type, class arg_type1, class arg_type2> +void test_binary_function () +{ + static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); + static_assert((std::is_same<typename F::first_argument_type, arg_type1>::value), "" ); + static_assert((std::is_same<typename F::second_argument_type, arg_type2>::value), "" ); + static_assert((!has_argument_type<F>::value), "" ); +} + +template <class F, class return_type> +void test_other_function () +{ + static_assert((std::is_same<typename F::result_type, return_type>::value), "" ); + static_assert((!has_argument_type<F>::value), "" ); + static_assert((!has_first_argument_type<F>::value), "" ); + static_assert((!has_second_argument_type<F>::value), "" ); +} + +int main() +{ + test_nullary_function<std::function<int()>, int>(); + test_unary_function <std::function<double(int)>, double, int>(); + test_binary_function <std::function<double(int, char)>, double, int, char>(); + test_other_function <std::function<double(int, char, double)>, double>(); +} diff --git a/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp b/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/function.objects/logical.operations/logical_and.pass.cpp b/test/std/utilities/function.objects/logical.operations/logical_and.pass.cpp new file mode 100644 index 0000000000000..72f9dc20144de --- /dev/null +++ b/test/std/utilities/function.objects/logical.operations/logical_and.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_and + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_and<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(f(36, 36)); + assert(!f(36, 0)); + assert(!f(0, 36)); + assert(!f(0, 0)); +#if _LIBCPP_STD_VER > 11 + typedef std::logical_and<> F2; + const F2 f2 = F2(); + assert( f2(36, 36)); + assert( f2(36, 36L)); + assert( f2(36L, 36)); + assert(!f2(36, 0)); + assert(!f2(0, 36)); + assert( f2(36, 36L)); + assert(!f2(36, 0L)); + assert(!f2(0, 36L)); + assert( f2(36L, 36)); + assert(!f2(36L, 0)); + assert(!f2(0L, 36)); + + constexpr bool foo = std::logical_and<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::logical_and<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/logical.operations/logical_not.pass.cpp b/test/std/utilities/function.objects/logical.operations/logical_not.pass.cpp new file mode 100644 index 0000000000000..8484625a727c1 --- /dev/null +++ b/test/std/utilities/function.objects/logical.operations/logical_not.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_not + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_not<int> F; + const F f = F(); + static_assert((std::is_same<F::argument_type, int>::value), "" ); + static_assert((std::is_same<F::result_type, bool>::value), "" ); + assert(!f(36)); + assert(f(0)); +#if _LIBCPP_STD_VER > 11 + typedef std::logical_not<> F2; + const F2 f2 = F2(); + assert(!f2(36)); + assert( f2(0)); + assert(!f2(36L)); + assert( f2(0L)); + + constexpr bool foo = std::logical_not<int> () (36); + static_assert ( !foo, "" ); + + constexpr bool bar = std::logical_not<> () (36); + static_assert ( !bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/logical.operations/logical_or.pass.cpp b/test/std/utilities/function.objects/logical.operations/logical_or.pass.cpp new file mode 100644 index 0000000000000..7280504403f48 --- /dev/null +++ b/test/std/utilities/function.objects/logical.operations/logical_or.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// logical_or + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::logical_or<int> F; + const F f = F(); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(f(36, 36)); + assert(f(36, 0)); + assert(f(0, 36)); + assert(!f(0, 0)); +#if _LIBCPP_STD_VER > 11 + typedef std::logical_or<> F2; + const F2 f2 = F2(); + assert( f2(36, 36)); + assert( f2(36, 36L)); + assert( f2(36L, 36)); + assert( f2(36, 0)); + assert( f2(0, 36)); + assert( f2(36, 0L)); + assert( f2(0, 36L)); + assert(!f2(0, 0)); + assert(!f2(0, 0L)); + assert(!f2(0L, 0)); + + constexpr bool foo = std::logical_or<int> () (36, 36); + static_assert ( foo, "" ); + + constexpr bool bar = std::logical_or<> () (36.0, 36); + static_assert ( bar, "" ); +#endif +} diff --git a/test/std/utilities/function.objects/logical.operations/transparent.pass.cpp b/test/std/utilities/function.objects/logical.operations/transparent.pass.cpp new file mode 100644 index 0000000000000..6e3b7a2eee246 --- /dev/null +++ b/test/std/utilities/function.objects/logical.operations/transparent.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +#include <functional> +#include <string> + +template <class _Tp> +struct is_transparent +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::is_transparent* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + + +int main () { +#if _LIBCPP_STD_VER > 11 + + static_assert ( !is_transparent<std::logical_and<int>>::value, "" ); + static_assert ( !is_transparent<std::logical_and<std::string>>::value, "" ); + static_assert ( is_transparent<std::logical_and<void>>::value, "" ); + static_assert ( is_transparent<std::logical_and<>>::value, "" ); + + static_assert ( !is_transparent<std::logical_or<int>>::value, "" ); + static_assert ( !is_transparent<std::logical_or<std::string>>::value, "" ); + static_assert ( is_transparent<std::logical_or<void>>::value, "" ); + static_assert ( is_transparent<std::logical_or<>>::value, "" ); + + static_assert ( !is_transparent<std::logical_not<int>>::value, "" ); + static_assert ( !is_transparent<std::logical_not<std::string>>::value, "" ); + static_assert ( is_transparent<std::logical_not<void>>::value, "" ); + static_assert ( is_transparent<std::logical_not<>>::value, "" ); + +#endif + + return 0; + } diff --git a/test/std/utilities/function.objects/negators/binary_negate.pass.cpp b/test/std/utilities/function.objects/negators/binary_negate.pass.cpp new file mode 100644 index 0000000000000..53ff5b47a3a06 --- /dev/null +++ b/test/std/utilities/function.objects/negators/binary_negate.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// binary_negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::binary_negate<std::logical_and<int> > F; + const F f = F(std::logical_and<int>()); + static_assert((std::is_same<int, F::first_argument_type>::value), "" ); + static_assert((std::is_same<int, F::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, F::result_type>::value), "" ); + assert(!f(36, 36)); + assert( f(36, 0)); + assert( f(0, 36)); + assert( f(0, 0)); +} diff --git a/test/std/utilities/function.objects/negators/not1.pass.cpp b/test/std/utilities/function.objects/negators/not1.pass.cpp new file mode 100644 index 0000000000000..f6ac7a49dc003 --- /dev/null +++ b/test/std/utilities/function.objects/negators/not1.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not1 + +#include <functional> +#include <cassert> + +int main() +{ + typedef std::logical_not<int> F; + assert(std::not1(F())(36)); + assert(!std::not1(F())(0)); +} diff --git a/test/std/utilities/function.objects/negators/not2.pass.cpp b/test/std/utilities/function.objects/negators/not2.pass.cpp new file mode 100644 index 0000000000000..7541753d568ed --- /dev/null +++ b/test/std/utilities/function.objects/negators/not2.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not2 + +#include <functional> +#include <cassert> + +int main() +{ + typedef std::logical_and<int> F; + assert(!std::not2(F())(36, 36)); + assert( std::not2(F())(36, 0)); + assert( std::not2(F())(0, 36)); + assert( std::not2(F())(0, 0)); +} diff --git a/test/std/utilities/function.objects/negators/unary_negate.pass.cpp b/test/std/utilities/function.objects/negators/unary_negate.pass.cpp new file mode 100644 index 0000000000000..e2498a3b52e2f --- /dev/null +++ b/test/std/utilities/function.objects/negators/unary_negate.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// unary_negate + +#include <functional> +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::unary_negate<std::logical_not<int> > F; + const F f = F(std::logical_not<int>()); + static_assert((std::is_same<F::argument_type, int>::value), "" ); + static_assert((std::is_same<F::result_type, bool>::value), "" ); + assert(f(36)); + assert(!f(0)); +} diff --git a/test/std/utilities/function.objects/refwrap/binary.pass.cpp b/test/std/utilities/function.objects/refwrap/binary.pass.cpp new file mode 100644 index 0000000000000..579e81fe69e66 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/binary.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from binary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((!std::is_base_of<std::binary_function<int, char, int>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float ()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>, + std::reference_wrapper<float(C::*)(int) const volatile> >::value), ""); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp new file mode 100644 index 0000000000000..df0b55a5d0609 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// operator T& () const; + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T& r2 = r; + assert(&r2 == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp new file mode 100644 index 0000000000000..122716a23a8b5 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.assign/copy_assign.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper& operator=(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + T t2 = t; + std::reference_wrapper<T> r2(t2); + r2 = r; + assert(&r2.get() == &t); +} + +void f() {} +void g() {} + +void +test_function() +{ + std::reference_wrapper<void ()> r(f); + std::reference_wrapper<void ()> r2(g); + r2 = r; + assert(&r2.get() == &f); +} + +int main() +{ + void (*fp)() = f; + test(fp); + test_function(); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp new file mode 100644 index 0000000000000..721a442d44311 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.const/copy_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(const reference_wrapper<T>& x); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + std::reference_wrapper<T> r2 = r; + assert(&r2.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp b/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp new file mode 100644 index 0000000000000..ba46946aae1bf --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T&&) = delete; + +#include <functional> +#include <cassert> + +int main() +{ + std::reference_wrapper<const int> r(3); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp new file mode 100644 index 0000000000000..564a3f77433c3 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.const/type_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// reference_wrapper(T& t); + +#include <functional> +#include <cassert> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +template <class T> +void +test(T& t) +{ + std::reference_wrapper<T> r(t); + assert(&r.get() == &t); +} + +void f() {} + +int main() +{ + void (*fp)() = f; + test(fp); + test(f); + functor1 f1; + test(f1); + int i = 0; + test(i); + const int j = 0; + test(j); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp new file mode 100644 index 0000000000000..f2ffd44e26b7c --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_1.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(const T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<const int> r = std::cref(i); + assert(&r.get() == &i); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp new file mode 100644 index 0000000000000..75875264479a5 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t); + +#include <functional> +#include <cassert> + +int main() +{ + const int i = 0; + std::reference_wrapper<const int> r1 = std::cref(i); + std::reference_wrapper<const int> r2 = std::cref(r1); + assert(&r2.get() == &i); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp new file mode 100644 index 0000000000000..86a5696f48cad --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +// Don't allow binding to a temp + +#include <functional> + +struct A {}; + +const A source() {return A();} + +int main() +{ + std::reference_wrapper<const A> r = std::ref(source()); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp new file mode 100644 index 0000000000000..39aa4843a710a --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_1.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(T& t); + +#include <functional> +#include <cassert> + +int main() +{ + int i = 0; + std::reference_wrapper<int> r = std::ref(i); + assert(&r.get() == &i); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp new file mode 100644 index 0000000000000..4033e676f018f --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t); + +#include <functional> +#include <cassert> + +#include "counting_predicates.hpp" + +bool is5 ( int i ) { return i == 5; } + +template <typename T> +bool call_pred ( T pred ) { return pred(5); } + +int main() +{ + { + int i = 0; + std::reference_wrapper<int> r1 = std::ref(i); + std::reference_wrapper<int> r2 = std::ref(r1); + assert(&r2.get() == &i); + } + { + unary_counting_predicate<bool(*)(int), int> cp(is5); + assert(!cp(6)); + assert(cp.count() == 1); + assert(call_pred(cp)); + assert(cp.count() == 1); + assert(call_pred(std::ref(cp))); + assert(cp.count() == 2); + } +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp new file mode 100644 index 0000000000000..551562721e3e7 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// member data pointer: cv qualifiers should transfer from argument to return type + +struct A_int_1 +{ + A_int_1() : data_(5) {} + + int data_; +}; + +void +test_int_1() +{ + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + const A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(ap) == 7); + } +} + +int main() +{ + test_int_1(); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp new file mode 100644 index 0000000000000..a9edf00ee5924 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.pass.cpp @@ -0,0 +1,329 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +int count = 0; + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } + + void mem1() {++count;} + void mem2() const {++count;} +}; + +void +test_void_1() +{ + int save_count = count; + // function + { + std::reference_wrapper<void (int)> r1(f_void_1); + int i = 2; + r1(i); + assert(count == save_count+2); + save_count = count; + } + // function pointer + { + void (*fp)(int) = f_void_1; + std::reference_wrapper<void (*)(int)> r1(fp); + int i = 3; + r1(i); + assert(count == save_count+3); + save_count = count; + } + // functor + { + A_void_1 a0; + std::reference_wrapper<A_void_1> r1(a0); + int i = 4; + r1(i); + assert(count == save_count+4); + save_count = count; + } + // member function pointer + { + void (A_void_1::*fp)() = &A_void_1::mem1; + std::reference_wrapper<void (A_void_1::*)()> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + r1(ap); + assert(count == save_count+1); + save_count = count; + } + // const member function pointer + { + void (A_void_1::*fp)() const = &A_void_1::mem2; + std::reference_wrapper<void (A_void_1::*)() const> r1(fp); + A_void_1 a; + r1(a); + assert(count == save_count+1); + save_count = count; + A_void_1* ap = &a; + r1(ap); + assert(count == save_count+1); + save_count = count; + } +} + +// 1 arg, return int + +int f_int_1(int i) +{ + return i + 1; +} + +struct A_int_1 +{ + A_int_1() : data_(5) {} + int operator()(int i) + { + return i - 1; + } + + int mem1() {return 3;} + int mem2() const {return 4;} + int data_; +}; + +void +test_int_1() +{ + // function + { + std::reference_wrapper<int (int)> r1(f_int_1); + int i = 2; + assert(r1(i) == 3); + } + // function pointer + { + int (*fp)(int) = f_int_1; + std::reference_wrapper<int (*)(int)> r1(fp); + int i = 3; + assert(r1(i) == 4); + } + // functor + { + A_int_1 a0; + std::reference_wrapper<A_int_1> r1(a0); + int i = 4; + assert(r1(i) == 3); + } + // member function pointer + { + int (A_int_1::*fp)() = &A_int_1::mem1; + std::reference_wrapper<int (A_int_1::*)()> r1(fp); + A_int_1 a; + assert(r1(a) == 3); + A_int_1* ap = &a; + assert(r1(ap) == 3); + } + // const member function pointer + { + int (A_int_1::*fp)() const = &A_int_1::mem2; + std::reference_wrapper<int (A_int_1::*)() const> r1(fp); + A_int_1 a; + assert(r1(a) == 4); + A_int_1* ap = &a; + assert(r1(ap) == 4); + } + // member data pointer + { + int A_int_1::*fp = &A_int_1::data_; + std::reference_wrapper<int A_int_1::*> r1(fp); + A_int_1 a; + assert(r1(a) == 5); + r1(a) = 6; + assert(r1(a) == 6); + A_int_1* ap = &a; + assert(r1(ap) == 6); + r1(ap) = 7; + assert(r1(ap) == 7); + } +} + +// 2 arg, return void + +void f_void_2(int i, int j) +{ + count += i+j; +} + +struct A_void_2 +{ + void operator()(int i, int j) + { + count += i+j; + } + + void mem1(int i) {count += i;} + void mem2(int i) const {count += i;} +}; + +void +test_void_2() +{ + int save_count = count; + // function + { + std::reference_wrapper<void (int, int)> r1(f_void_2); + int i = 2; + int j = 3; + r1(i, j); + assert(count == save_count+5); + save_count = count; + } + // function pointer + { + void (*fp)(int, int) = f_void_2; + std::reference_wrapper<void (*)(int, int)> r1(fp); + int i = 3; + int j = 4; + r1(i, j); + assert(count == save_count+7); + save_count = count; + } + // functor + { + A_void_2 a0; + std::reference_wrapper<A_void_2> r1(a0); + int i = 4; + int j = 5; + r1(i, j); + assert(count == save_count+9); + save_count = count; + } + // member function pointer + { + void (A_void_2::*fp)(int) = &A_void_2::mem1; + std::reference_wrapper<void (A_void_2::*)(int)> r1(fp); + A_void_2 a; + int i = 3; + r1(a, i); + assert(count == save_count+3); + save_count = count; + A_void_2* ap = &a; + r1(ap, i); + assert(count == save_count+3); + save_count = count; + } + // const member function pointer + { + void (A_void_2::*fp)(int) const = &A_void_2::mem2; + std::reference_wrapper<void (A_void_2::*)(int) const> r1(fp); + A_void_2 a; + int i = 4; + r1(a, i); + assert(count == save_count+4); + save_count = count; + A_void_2* ap = &a; + r1(ap, i); + assert(count == save_count+4); + save_count = count; + } +} + +// 2 arg, return int + +int f_int_2(int i, int j) +{ + return i+j; +} + +struct A_int_2 +{ + int operator()(int i, int j) + { + return i+j; + } + + int mem1(int i) {return i+1;} + int mem2(int i) const {return i+2;} +}; + +void +testint_2() +{ + // function + { + std::reference_wrapper<int (int, int)> r1(f_int_2); + int i = 2; + int j = 3; + assert(r1(i, j) == i+j); + } + // function pointer + { + int (*fp)(int, int) = f_int_2; + std::reference_wrapper<int (*)(int, int)> r1(fp); + int i = 3; + int j = 4; + assert(r1(i, j) == i+j); + } + // functor + { + A_int_2 a0; + std::reference_wrapper<A_int_2> r1(a0); + int i = 4; + int j = 5; + assert(r1(i, j) == i+j); + } + // member function pointer + { + int(A_int_2::*fp)(int) = &A_int_2::mem1; + std::reference_wrapper<int (A_int_2::*)(int)> r1(fp); + A_int_2 a; + int i = 3; + assert(r1(a, i) == i+1); + A_int_2* ap = &a; + assert(r1(ap, i) == i+1); + } + // const member function pointer + { + int (A_int_2::*fp)(int) const = &A_int_2::mem2; + std::reference_wrapper<int (A_int_2::*)(int) const> r1(fp); + A_int_2 a; + int i = 4; + assert(r1(a, i) == i+2); + A_int_2* ap = &a; + assert(r1(ap, i) == i+2); + } +} + +int main() +{ + test_void_1(); + test_int_1(); + test_void_2(); + testint_2(); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp new file mode 100644 index 0000000000000..61357a7fa394f --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// 0 args, return int + +int count = 0; + +int f_int_0() +{ + return 3; +} + +struct A_int_0 +{ + int operator()() {return 4;} +}; + +void +test_int_0() +{ + // function + { + std::reference_wrapper<int ()> r1(f_int_0); + assert(r1() == 3); + } + // function pointer + { + int (*fp)() = f_int_0; + std::reference_wrapper<int (*)()> r1(fp); + assert(r1() == 3); + } + // functor + { + A_int_0 a0; + std::reference_wrapper<A_int_0> r1(a0); + assert(r1() == 4); + } +} + +// 1 arg, return void + +void f_void_1(int i) +{ + count += i; +} + +struct A_void_1 +{ + void operator()(int i) + { + count += i; + } +}; + +int main() +{ + test_int_0(); +} diff --git a/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp new file mode 100644 index 0000000000000..8d700508cdc13 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_void_0.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// template <class... ArgTypes> +// requires Callable<T, ArgTypes&&...> +// Callable<T, ArgTypes&&...>::result_type +// operator()(ArgTypes&&... args) const; + +#include <functional> +#include <cassert> + +// 0 args, return void + +int count = 0; + +void f_void_0() +{ + ++count; +} + +struct A_void_0 +{ + void operator()() {++count;} +}; + +void +test_void_0() +{ + int save_count = count; + // function + { + std::reference_wrapper<void ()> r1(f_void_0); + r1(); + assert(count == save_count+1); + save_count = count; + } + // function pointer + { + void (*fp)() = f_void_0; + std::reference_wrapper<void (*)()> r1(fp); + r1(); + assert(count == save_count+1); + save_count = count; + } + // functor + { + A_void_0 a0; + std::reference_wrapper<A_void_0> r1(a0); + r1(); + assert(count == save_count+1); + save_count = count; + } +} + +int main() +{ + test_void_0(); +} diff --git a/test/std/utilities/function.objects/refwrap/type.pass.cpp b/test/std/utilities/function.objects/refwrap/type.pass.cpp new file mode 100644 index 0000000000000..68e406798145d --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/type.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for member typedef type + +#include <functional> +#include <type_traits> + +class C {}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<C>::type, + C>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void ()>::type, + void ()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int* (double*)>::type, + int* (double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::type, + void(*)()>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::type, + int*(*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::type, + int*(C::*)(double*)>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::type, + int (C::*)(double*) const volatile>::value), ""); +} diff --git a/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp b/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp new file mode 100644 index 0000000000000..61e0bfa162d89 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// Test that reference wrapper meets the requirements of TriviallyCopyable, +// CopyConstructible and CopyAssignable. + +#include <functional> +#include <type_traits> +#include <string> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} +}; +#endif + + +template <class T> +void test() +{ + typedef std::reference_wrapper<T> Wrap; + static_assert(std::is_copy_constructible<Wrap>::value, ""); + static_assert(std::is_copy_assignable<Wrap>::value, ""); + // Extension up for standardization: See N4151. + static_assert(std::is_trivially_copyable<Wrap>::value, ""); +} + +int main() +{ + test<int>(); + test<double>(); + test<std::string>(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test<MoveOnly>(); +#endif +} diff --git a/test/std/utilities/function.objects/refwrap/unary.pass.cpp b/test/std/utilities/function.objects/refwrap/unary.pass.cpp new file mode 100644 index 0000000000000..528a8f327d966 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/unary.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from unary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((std::is_base_of<std::unary_function<int, char>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<char, int>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<const volatile C*, float>, + std::reference_wrapper<float(C::*)() const volatile> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); +} diff --git a/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp b/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp new file mode 100644 index 0000000000000..609094dae4061 --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/weak_result.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// has weak result type + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<char, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<char, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +class C {}; + +template <class T> +struct has_result_type +{ +private: + struct two {char _; char __;}; + template <class U> static two test(...); + template <class U> static char test(typename U::result_type* = 0); +public: + static const bool value = sizeof(test<T>(0)) == 1; +}; + +int main() +{ + static_assert((std::is_same<std::reference_wrapper<functor1>::result_type, + char>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor2>::result_type, + double>::value), ""); + static_assert((std::is_same<std::reference_wrapper<functor3>::result_type, + float>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type, + void>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type, + int*>::value), ""); + static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type, + int>::value), ""); + static_assert((std::is_same<std::reference_wrapper<C()>::result_type, + C>::value), ""); + static_assert(has_result_type<std::reference_wrapper<functor3> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<functor4> >::value, ""); + static_assert(!has_result_type<std::reference_wrapper<C> >::value, ""); +} diff --git a/test/std/utilities/function.objects/unord.hash/enum.fail.cpp b/test/std/utilities/function.objects/unord.hash/enum.fail.cpp new file mode 100644 index 0000000000000..9e44bfb778176 --- /dev/null +++ b/test/std/utilities/function.objects/unord.hash/enum.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// Hashing a struct w/o a defined hash should fail. + +#include <functional> +#include <cassert> +#include <type_traits> + +struct X {}; + +int main() +{ + X x; + size_t h = std::hash<X>{} ( x ); +} diff --git a/test/std/utilities/function.objects/unord.hash/enum.pass.cpp b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp new file mode 100644 index 0000000000000..bd92a4ac4d2e1 --- /dev/null +++ b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// make sure that we can hash enumeration values +// Not very portable + +#if __cplusplus >= 201402L + +#include <functional> +#include <cassert> +#include <type_traits> +#include <limits> + +enum class Colors { red, orange, yellow, green, blue, indigo, violet }; +enum class Cardinals { zero, one, two, three, five=5 }; +enum class LongColors : short { red, orange, yellow, green, blue, indigo, violet }; +enum class ShortColors : long { red, orange, yellow, green, blue, indigo, violet }; +enum class EightBitColors : uint8_t { red, orange, yellow, green, blue, indigo, violet }; + +enum Fruits { apple, pear, grape, mango, cantaloupe }; + +template <class T> +void +test() +{ + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + typedef typename std::underlying_type<T>::type under_type; + + H h1; + std::hash<under_type> h2; + for (int i = 0; i <= 5; ++i) + { + T t(static_cast<T> (i)); + if (sizeof(T) <= sizeof(std::size_t)) + assert(h1(t) == h2(static_cast<under_type>(i))); + } +} + +int main() +{ + test<Cardinals>(); + + test<Colors>(); + test<ShortColors>(); + test<LongColors>(); + test<EightBitColors>(); + + test<Fruits>(); +} +#else +int main () {} +#endif diff --git a/test/std/utilities/function.objects/unord.hash/floating.pass.cpp b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp new file mode 100644 index 0000000000000..f1f198f235996 --- /dev/null +++ b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include <functional> +#include <cassert> +#include <type_traits> +#include <limits> +#include <cmath> + +template <class T> +void +test() +{ + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + H h; + + std::size_t t0 = h(0.); + std::size_t tn0 = h(-0.); + std::size_t tp1 = h(0.1); + std::size_t t1 = h(1); + std::size_t tn1 = h(-1); + std::size_t pinf = h(INFINITY); + std::size_t ninf = h(-INFINITY); + assert(t0 == tn0); + assert(t0 != tp1); + assert(t0 != t1); + assert(t0 != tn1); + assert(t0 != pinf); + assert(t0 != ninf); + + assert(tp1 != t1); + assert(tp1 != tn1); + assert(tp1 != pinf); + assert(tp1 != ninf); + + assert(t1 != tn1); + assert(t1 != pinf); + assert(t1 != ninf); + + assert(tn1 != pinf); + assert(tn1 != ninf); + + assert(pinf != ninf); +} + +int main() +{ + test<float>(); + test<double>(); + test<long double>(); +} diff --git a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp new file mode 100644 index 0000000000000..7cd9f15e93d11 --- /dev/null +++ b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include <functional> +#include <cassert> +#include <type_traits> +#include <limits> + +template <class T> +void +test() +{ + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + H h; + + for (int i = 0; i <= 5; ++i) + { + T t(i); + if (sizeof(T) <= sizeof(std::size_t)) + assert(h(t) == t); + } +} + +int main() +{ + test<bool>(); + test<char>(); + test<signed char>(); + test<unsigned char>(); + test<char16_t>(); + test<char32_t>(); + test<wchar_t>(); + test<short>(); + test<unsigned short>(); + test<int>(); + test<unsigned int>(); + test<long>(); + test<unsigned long>(); + test<long long>(); + test<unsigned long long>(); +} diff --git a/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp new file mode 100644 index 0000000000000..a48394495e2d5 --- /dev/null +++ b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include <functional> +#include <cassert> +#include <type_traits> +#include <limits> + +template <class T> +void +test() +{ + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + H h; + + typedef typename std::remove_pointer<T>::type type; + type i; + type j; + assert(h(&i) != h(&j)); +} + +int main() +{ + test<int*>(); +} diff --git a/test/std/utilities/function.objects/version.pass.cpp b/test/std/utilities/function.objects/version.pass.cpp new file mode 100644 index 0000000000000..99d731a74543c --- /dev/null +++ b/test/std/utilities/function.objects/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +#include <functional> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/intseq/intseq.general/integer_seq.pass.cpp b/test/std/utilities/intseq/intseq.general/integer_seq.pass.cpp new file mode 100644 index 0000000000000..8ca5a96a4fac7 --- /dev/null +++ b/test/std/utilities/intseq/intseq.general/integer_seq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// class make_integer_sequence + +#include <tuple> +#include <utility> +#include <type_traits> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +template <typename AtContainer, typename T, T... I> +auto extract ( const AtContainer &t, const std::integer_sequence<T, I...> idx ) +-> decltype ( std::make_tuple ( std::get<I>(t)... )) +{ return std::make_tuple ( std::get<I>(t)... ); } + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + +// Make a couple of sequences + using int3 = std::make_integer_sequence<int, 3>; // generates int: 0,1,2 + using size7 = std::make_integer_sequence<size_t, 7>; // generates size_t: 0,1,2,3,4,5,6 + using size4 = std::make_index_sequence<4>; // generates size_t: 0,1,2,3 + using size2 = std::index_sequence_for<int, size_t>; // generates size_t: 0,1 + using intmix = std::integer_sequence<int, 9, 8, 7, 2>; // generates int: 9,8,7,2 + using sizemix = std::index_sequence<1, 1, 2, 3, 5>; // generates size_t: 1,1,2,3,5 + +// Make sure they're what we expect + static_assert ( std::is_same<int3::value_type, int>::value, "int3 type wrong" ); + static_assert ( int3::size () == 3, "int3 size wrong" ); + + static_assert ( std::is_same<size7::value_type, size_t>::value, "size7 type wrong" ); + static_assert ( size7::size () == 7, "size7 size wrong" ); + + static_assert ( std::is_same<size4::value_type, size_t>::value, "size4 type wrong" ); + static_assert ( size4::size () == 4, "size4 size wrong" ); + + static_assert ( std::is_same<size2::value_type, size_t>::value, "size2 type wrong" ); + static_assert ( size2::size () == 2, "size2 size wrong" ); + + static_assert ( std::is_same<intmix::value_type, int>::value, "intmix type wrong" ); + static_assert ( intmix::size () == 4, "intmix size wrong" ); + + static_assert ( std::is_same<sizemix::value_type, size_t>::value, "sizemix type wrong" ); + static_assert ( sizemix::size () == 5, "sizemix size wrong" ); + + auto tup = std::make_tuple ( 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ); + +// Use them + auto t3 = extract ( tup, int3() ); + static_assert ( std::tuple_size<decltype(t3)>::value == int3::size (), "t3 size wrong"); + assert ( t3 == std::make_tuple ( 10, 11, 12 )); + + auto t7 = extract ( tup, size7 ()); + static_assert ( std::tuple_size<decltype(t7)>::value == size7::size (), "t7 size wrong"); + assert ( t7 == std::make_tuple ( 10, 11, 12, 13, 14, 15, 16 )); + + auto t4 = extract ( tup, size4 ()); + static_assert ( std::tuple_size<decltype(t4)>::value == size4::size (), "t4 size wrong"); + assert ( t4 == std::make_tuple ( 10, 11, 12, 13 )); + + auto t2 = extract ( tup, size2 ()); + static_assert ( std::tuple_size<decltype(t2)>::value == size2::size (), "t2 size wrong"); + assert ( t2 == std::make_tuple ( 10, 11 )); + + auto tintmix = extract ( tup, intmix ()); + static_assert ( std::tuple_size<decltype(tintmix)>::value == intmix::size (), "tintmix size wrong"); + assert ( tintmix == std::make_tuple ( 19, 18, 17, 12 )); + + auto tsizemix = extract ( tup, sizemix ()); + static_assert ( std::tuple_size<decltype(tsizemix)>::value == sizemix::size (), "tsizemix size wrong"); + assert ( tsizemix == std::make_tuple ( 11, 11, 12, 13, 15 )); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/intseq/intseq.intseq/integer_seq.fail.cpp b/test/std/utilities/intseq/intseq.intseq/integer_seq.fail.cpp new file mode 100644 index 0000000000000..4b2d1acb5e6b4 --- /dev/null +++ b/test/std/utilities/intseq/intseq.intseq/integer_seq.fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T, T... I> +// struct integer_sequence +// { +// typedef T type; +// +// static constexpr size_t size() noexcept; +// }; + +// This test is a conforming extension. The extension turns undefined behavior +// into a compile-time error. + +#include <utility> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + +// Should fail to compile, since float is not an integral type + using floatmix = std::integer_sequence<float>; + floatmix::value_type I; + +#else + +X + +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/intseq/intseq.intseq/integer_seq.pass.cpp b/test/std/utilities/intseq/intseq.intseq/integer_seq.pass.cpp new file mode 100644 index 0000000000000..a795e90c41e40 --- /dev/null +++ b/test/std/utilities/intseq/intseq.intseq/integer_seq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T, T... I> +// struct integer_sequence +// { +// typedef T type; +// +// static constexpr size_t size() noexcept; +// }; + +#include <utility> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + +// Make a few of sequences + using int3 = std::integer_sequence<int, 3, 2, 1>; + using size1 = std::integer_sequence<size_t, 7>; + using ushort2 = std::integer_sequence<unsigned short, 4, 6>; + using bool0 = std::integer_sequence<bool>; + +// Make sure they're what we expect + static_assert ( std::is_same<int3::value_type, int>::value, "int3 type wrong" ); + static_assert ( int3::size() == 3, "int3 size wrong" ); + + static_assert ( std::is_same<size1::value_type, size_t>::value, "size1 type wrong" ); + static_assert ( size1::size() == 1, "size1 size wrong" ); + + static_assert ( std::is_same<ushort2::value_type, unsigned short>::value, "ushort2 type wrong" ); + static_assert ( ushort2::size() == 2, "ushort2 size wrong" ); + + static_assert ( std::is_same<bool0::value_type, bool>::value, "bool0 type wrong" ); + static_assert ( bool0::size() == 0, "bool0 size wrong" ); + +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp new file mode 100644 index 0000000000000..2dd6c17b3deed --- /dev/null +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T, T N> +// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; + +#include <utility> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + + std::make_integer_sequence<int, -3>::value_type i; + +#else + +X + +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp new file mode 100644 index 0000000000000..7e82b94a7da01 --- /dev/null +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T, T N> +// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; + +#include <utility> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + + static_assert(std::is_same<std::make_integer_sequence<int, 0>, std::integer_sequence<int>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<int, 1>, std::integer_sequence<int, 0>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<int, 2>, std::integer_sequence<int, 0, 1>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<int, 3>, std::integer_sequence<int, 0, 1, 2>>::value, ""); + + static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 0>, std::integer_sequence<unsigned long long>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 1>, std::integer_sequence<unsigned long long, 0>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 2>, std::integer_sequence<unsigned long long, 0, 1>>::value, ""); + static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 3>, std::integer_sequence<unsigned long long, 0, 1, 2>>::value, ""); + +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/intseq/nothing_to_do.pass.cpp b/test/std/utilities/intseq/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/intseq/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp b/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp new file mode 100644 index 0000000000000..636998aa0d726 --- /dev/null +++ b/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// struct allocator_arg_t { }; +// const allocator_arg_t allocator_arg = allocator_arg_t(); + +#include <memory> + +void test(std::allocator_arg_t) {} + +int main() +{ + test(std::allocator_arg); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp new file mode 100644 index 0000000000000..490fdf5d332bb --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// static pointer allocate(allocator_type& a, size_type n); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 10); + return (value_type*)0xDEADBEEF; + } +}; + +int main() +{ + A<int> a; + assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp new file mode 100644 index 0000000000000..079db3526ac78 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 10); + return (value_type*)0xDEADBEEF; + } +}; + +template <class T> +struct B +{ + typedef T value_type; + + value_type* allocate(std::size_t n) + { + assert(n == 12); + return (value_type*)0xEEADBEEF; + } + value_type* allocate(std::size_t n, const void* p) + { + assert(n == 11); + assert(p == 0); + return (value_type*)0xFEADBEEF; + } +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + A<int> a; + assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF); +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE + B<int> b; + assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp new file mode 100644 index 0000000000000..634019758e703 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp @@ -0,0 +1,143 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// template <class Ptr, class... Args> +// static void construct(allocator_type& a, Ptr p, Args&&... args); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +int b_construct = 0; + +template <class T> +struct B +{ + typedef T value_type; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class U, class ...Args> + void construct(U* p, Args&& ...args) + { + ++b_construct; + ::new ((void*)p) U(std::forward<Args>(args)...); + } +#endif // _LIBCPP_HAS_NO_VARIADICS +}; + +struct A0 +{ + static int count; + A0() {++count;} +}; + +int A0::count = 0; + +struct A1 +{ + static int count; + A1(char c) + { + assert(c == 'c'); + ++count; + } +}; + +int A1::count = 0; + +struct A2 +{ + static int count; + A2(char c, int i) + { + assert(c == 'd'); + assert(i == 5); + ++count; + } +}; + +int A2::count = 0; + +int main() +{ + { + A0::count = 0; + A<int> a; + std::aligned_storage<sizeof(A0)>::type a0; + assert(A0::count == 0); + std::allocator_traits<A<int> >::construct(a, (A0*)&a0); + assert(A0::count == 1); + } + { + A1::count = 0; + A<int> a; + std::aligned_storage<sizeof(A1)>::type a1; + assert(A1::count == 0); + std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c'); + assert(A1::count == 1); + } + { + A2::count = 0; + A<int> a; + std::aligned_storage<sizeof(A2)>::type a2; + assert(A2::count == 0); + std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5); + assert(A2::count == 1); + } +#ifndef _LIBCPP_HAS_NO_VARIADICS + { + A0::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A0)>::type a0; + assert(A0::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A0*)&a0); + assert(A0::count == 1); + assert(b_construct == 1); + } + { + A1::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A1)>::type a1; + assert(A1::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c'); + assert(A1::count == 1); + assert(b_construct == 1); + } + { + A2::count = 0; + b_construct = 0; + B<int> b; + std::aligned_storage<sizeof(A2)>::type a2; + assert(A2::count == 0); + assert(b_construct == 0); + std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5); + assert(A2::count == 1); + assert(b_construct == 1); + } +#endif // _LIBCPP_HAS_NO_VARIADICS +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp new file mode 100644 index 0000000000000..b137dc6d36c3d --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// static void deallocate(allocator_type& a, pointer p, size_type n); +// ... +// }; + +#include <memory> +#include <cassert> + +int called = 0; + +template <class T> +struct A +{ + typedef T value_type; + + void deallocate(value_type* p, std::size_t n) + { + assert(p == (value_type*)0xDEADBEEF); + assert(n == 10); + ++called; + } +}; + +int main() +{ + A<int> a; + std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10); + assert(called == 1); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp new file mode 100644 index 0000000000000..54726c929efe6 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// template <class Ptr> +// static void destroy(allocator_type& a, Ptr p); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +int b_destroy = 0; + +template <class T> +struct B +{ + typedef T value_type; + + template <class U> + void destroy(U* p) + { + ++b_destroy; + p->~U(); + } +}; + +struct A0 +{ + static int count; + ~A0() {++count;} +}; + +int A0::count = 0; + +int main() +{ + { + A0::count = 0; + A<int> a; + std::aligned_storage<sizeof(A0)>::type a0; + std::allocator_traits<A<int> >::construct(a, (A0*)&a0); + assert(A0::count == 0); + std::allocator_traits<A<int> >::destroy(a, (A0*)&a0); + assert(A0::count == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + A0::count = 0; + b_destroy = 0; + B<int> b; + std::aligned_storage<sizeof(A0)>::type a0; + std::allocator_traits<B<int> >::construct(b, (A0*)&a0); + assert(A0::count == 0); + assert(b_destroy == 0); + std::allocator_traits<B<int> >::destroy(b, (A0*)&a0); + assert(A0::count == 1); + assert(b_destroy == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp new file mode 100644 index 0000000000000..1fa7291203ed4 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// static size_type max_size(const allocator_type& a) noexcept; +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + +}; + +template <class T> +struct B +{ + typedef T value_type; + + size_t max_size() const + { + return 100; + } +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + A<int> a; + assert(std::allocator_traits<A<int> >::max_size(a) == + std::numeric_limits<std::size_t>::max()); + } + { + const A<int> a = {}; + assert(std::allocator_traits<A<int> >::max_size(a) == + std::numeric_limits<std::size_t>::max()); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + B<int> b; + assert(std::allocator_traits<B<int> >::max_size(b) == 100); + } + { + const B<int> b = {}; + assert(std::allocator_traits<B<int> >::max_size(b) == 100); + } +#if __cplusplus >= 201103 + { + std::allocator<int> a; + static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, ""); + } +#endif +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp new file mode 100644 index 0000000000000..29fe2be126f3f --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// static allocator_type +// select_on_container_copy_construction(const allocator_type& a); +// ... +// }; + +#include <memory> +#include <new> +#include <type_traits> +#include <cassert> + +template <class T> +struct A +{ + typedef T value_type; + int id; + explicit A(int i = 0) : id(i) {} + +}; + +template <class T> +struct B +{ + typedef T value_type; + + int id; + explicit B(int i = 0) : id(i) {} + + B select_on_container_copy_construction() const + { + return B(100); + } +}; + +int main() +{ + { + A<int> a; + assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); + } + { + const A<int> a(0); + assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + B<int> b; + assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); + } + { + const B<int> b(0); + assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp new file mode 100644 index 0000000000000..20348d20c10cd --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::const_pointer +// | pointer_traits<pointer>::rebind<const value_type> +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<T> pointer; + typedef CPtr<const T> const_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp new file mode 100644 index 0000000000000..4b4045a51bae0 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::const_void_pointer +// | pointer_traits<pointer>::rebind<const void> +// const_void_pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<const void> const_void_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp new file mode 100644 index 0000000000000..085c911b07035 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::difference_type +// | pointer_traits<pointer>::difference_type difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef short difference_type; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct C +{ + typedef T value_type; + struct pointer {}; + struct const_pointer {}; + struct void_pointer {}; + struct const_void_pointer {}; +}; + +namespace std +{ + +template <> +struct pointer_traits<C<char>::pointer> +{ + typedef signed char difference_type; +}; + +} + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::difference_type, signed char>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp new file mode 100644 index 0000000000000..31a0f171d33d0 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::is_always_equal +// | is_empty is_always_equal; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct C +{ + typedef T value_type; + int not_empty_; // some random member variable +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::is_always_equal, std::false_type>::value), ""); + + static_assert((std::is_same<std::allocator_traits<A<const char> >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<const char> >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<const char> >::is_always_equal, std::false_type>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp new file mode 100644 index 0000000000000..60ba094993428 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// typedef Alloc::pointer | value_type* pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp new file mode 100644 index 0000000000000..604e890efaaee --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_copy_assignment +// | false_type propagate_on_container_copy_assignment; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_copy_assignment; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp new file mode 100644 index 0000000000000..1d2b18686d0f1 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_move_assignment +// | false_type propagate_on_container_move_assignment; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_move_assignment; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp new file mode 100644 index 0000000000000..6730d1ae261a6 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::propagate_on_container_swap +// | false_type propagate_on_container_swap; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp new file mode 100644 index 0000000000000..50611b99da9a8 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct ReboundA {}; + +template <class T> +struct A +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> other;}; +}; + +template <class T, class U> +struct ReboundB {}; + +template <class T, class U> +struct B +{ + typedef T value_type; + + template <class V> struct rebind {typedef ReboundB<V, U> other;}; +}; + +template <class T> +struct C +{ + typedef T value_type; +}; + +template <class T, class U> +struct D +{ + typedef T value_type; +}; + +template <class T> +struct E +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> otter;}; +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp new file mode 100644 index 0000000000000..e9c175fe86a54 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// typedef Alloc::size_type | size_t size_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; + typedef unsigned short size_type; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct C +{ + typedef T value_type; + struct pointer {}; + struct const_pointer {}; + struct void_pointer {}; + struct const_void_pointer {}; +}; + +namespace std +{ + +template <> +struct pointer_traits<C<char>::pointer> +{ + typedef signed char difference_type; +}; + +} + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, + std::make_unsigned<std::ptrdiff_t>::type>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::size_type, + unsigned char>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp new file mode 100644 index 0000000000000..74cd3475f6645 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc::void_pointer +// | pointer_traits<pointer>::rebind<void> +// void_pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct Ptr {}; + +template <class T> +struct A +{ + typedef T value_type; + typedef Ptr<T> pointer; +}; + +template <class T> +struct B +{ + typedef T value_type; +}; + +template <class T> +struct CPtr {}; + +template <class T> +struct C +{ + typedef T value_type; + typedef CPtr<void> void_pointer; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/allocator_type.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator_type.pass.cpp new file mode 100644 index 0000000000000..fe35ae487576c --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator_type.pass.cpp @@ -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> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc allocator_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), ""); +} diff --git a/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp b/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp new file mode 100644 index 0000000000000..87da9a0a85dab --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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 Alloc> +// struct allocator_traits +// { +// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct ReboundA {}; + +template <class T> +struct A +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> other;}; +}; + +template <class T, class U> +struct ReboundB {}; + +template <class T, class U> +struct B +{ + typedef T value_type; + + template <class V> struct rebind {typedef ReboundB<V, U> other;}; +}; + +template <class T> +struct C +{ + typedef T value_type; +}; + +template <class T, class U> +struct D +{ + typedef T value_type; +}; + +template <class T> +struct E +{ + typedef T value_type; + + template <class U> struct rebind {typedef ReboundA<U> otter;}; +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), ""); + static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/test/std/utilities/memory/allocator.traits/value_type.pass.cpp b/test/std/utilities/memory/allocator.traits/value_type.pass.cpp new file mode 100644 index 0000000000000..d0c3d2c09a1f2 --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/value_type.pass.cpp @@ -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> + +// template <class Alloc> +// struct allocator_traits +// { +// typedef typename Alloc::value_type value_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ + typedef T value_type; +}; + +int main() +{ + static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp b/test/std/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp b/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp new file mode 100644 index 0000000000000..0477d9912e6ec --- /dev/null +++ b/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 T, class Alloc> struct uses_allocator; + +#include <memory> +#include <vector> + +struct A +{ +}; + +struct B +{ + typedef int allocator_type; +}; + +int main() +{ + static_assert((!std::uses_allocator<int, std::allocator<int> >::value), ""); + static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<A, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<B, std::allocator<int> >::value), ""); + static_assert(( std::uses_allocator<B, double>::value), ""); +} diff --git a/test/std/utilities/memory/allocator.uses/nothing_to_do.pass.cpp b/test/std/utilities/memory/allocator.uses/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/allocator.uses/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/c.malloc/nothing_to_do.pass.cpp b/test/std/utilities/memory/c.malloc/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..a71806330062c --- /dev/null +++ b/test/std/utilities/memory/c.malloc/nothing_to_do.pass.cpp @@ -0,0 +1,14 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <cstdlib> and <cstring> are already tested elsewhere + +int main() +{ +} diff --git a/test/std/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp new file mode 100644 index 0000000000000..8ce49b90d4891 --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp @@ -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)); +} diff --git a/test/std/utilities/memory/default.allocator/allocator.members/address.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/address.pass.cpp new file mode 100644 index 0000000000000..04534f24d502e --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.members/address.pass.cpp @@ -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>(); +} diff --git a/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp new file mode 100644 index 0000000000000..253515e3db3c2 --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// pointer allocate(size_type n, allocator<void>::const_pointer hint=0); + +#include <memory> +#include <cassert> + +#include "count_new.hpp" + +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(globalMemCounter.checkOutstandingNewEq(0)); + assert(A_constructed == 0); + globalMemCounter.last_new_size = 0; + A* ap = a.allocate(3); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); + assert(A_constructed == 0); + a.deallocate(ap, 3); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(A_constructed == 0); + + globalMemCounter.last_new_size = 0; + A* ap2 = a.allocate(3, (const void*)5); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); + assert(A_constructed == 0); + a.deallocate(ap2, 3); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(A_constructed == 0); +} diff --git a/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp new file mode 100644 index 0000000000000..d0a870e60690c --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp @@ -0,0 +1,142 @@ +//===----------------------------------------------------------------------===// +// +// 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); + +#include <memory> +#include <cassert> + +#include "count_new.hpp" + +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(globalMemCounter.checkOutstandingNewEq(0)); + assert(A_constructed == 0); + + globalMemCounter.last_new_size = 0; + A* ap = a.allocate(3); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); + assert(A_constructed == 0); + + a.construct(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 0); + + a.construct(ap, A()); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 0); + + a.construct(ap, 5); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 0); + + a.construct(ap, 5, (int*)0); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(A_constructed == 0); + + a.deallocate(ap, 3); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(A_constructed == 0); + } + { + std::allocator<move_only> a; + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(move_only_constructed == 0); + + globalMemCounter.last_new_size = 0; + move_only* ap = a.allocate(3); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); + assert(move_only_constructed == 0); + + a.construct(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(move_only_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(move_only_constructed == 0); + + a.construct(ap, move_only()); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(move_only_constructed == 1); + + a.destroy(ap); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(move_only_constructed == 0); + + a.deallocate(ap, 3); + assert(globalMemCounter.checkOutstandingNewEq(0)); + assert(move_only_constructed == 0); + } +} diff --git a/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp new file mode 100644 index 0000000000000..6ec9339bc48ff --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp @@ -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()); +} diff --git a/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp b/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp new file mode 100644 index 0000000000000..5a8f7a28a042c --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp @@ -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 diff --git a/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp b/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp new file mode 100644 index 0000000000000..cba32103dcd47 --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <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; +// typedef true_type is_always_equal; +// +// 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), ""); + + static_assert((std::is_same<std::allocator< char>::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same<std::allocator<const char>::is_always_equal, std::true_type>::value), ""); + + std::allocator<char> a; + std::allocator<char> a2 = a; + a2 = a; + std::allocator<int> a3 = a2; + ((void)a3); +} diff --git a/test/std/utilities/memory/default.allocator/allocator_void.pass.cpp b/test/std/utilities/memory/default.allocator/allocator_void.pass.cpp new file mode 100644 index 0000000000000..cc1dbebae033c --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator_void.pass.cpp @@ -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; +} diff --git a/test/std/utilities/memory/pointer.traits/difference_type.pass.cpp b/test/std/utilities/memory/pointer.traits/difference_type.pass.cpp new file mode 100644 index 0000000000000..483c32561e85b --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/difference_type.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> +// struct pointer_traits<T*> +// { +// typedef ptrdiff_t difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::pointer_traits<double*>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/test/std/utilities/memory/pointer.traits/element_type.pass.cpp b/test/std/utilities/memory/pointer.traits/element_type.pass.cpp new file mode 100644 index 0000000000000..44694fcb013cf --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/element_type.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> +// struct pointer_traits<T*> +// { +// typedef T element_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::pointer_traits<const short*>::element_type, const short>::value), ""); +} diff --git a/test/std/utilities/memory/pointer.traits/pointer.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer.pass.cpp new file mode 100644 index 0000000000000..66e90cfcb8543 --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef Ptr pointer; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef short element_type; + typedef char difference_type; +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::pointer, A>::value), ""); + static_assert((std::is_same<std::pointer_traits<int*>::pointer, int*>::value), ""); +} diff --git a/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp new file mode 100644 index 0000000000000..a8ad936c9366f --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// static pointer pointer_to(<details>); +// ... +// }; + +#include <memory> +#include <cassert> + +template <class T> +struct A +{ +private: + struct nat {}; +public: + typedef T element_type; + element_type* t_; + + A(element_type* t) : t_(t) {} + + static A pointer_to(typename std::conditional<std::is_void<element_type>::value, + nat, element_type>::type& et) + {return A(&et);} +}; + +int main() +{ + { + int i = 0; + A<int> a = std::pointer_traits<A<int> >::pointer_to(i); + assert(a.t_ == &i); + } + { + (std::pointer_traits<A<void> >::element_type)0; + } +} diff --git a/test/std/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp new file mode 100644 index 0000000000000..4efe61342420c --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef <details> difference_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef short element_type; + typedef char difference_type; +}; + +struct B +{ + typedef short element_type; +}; + +template <class T> +struct C {}; + +template <class T> +struct D +{ + typedef char difference_type; +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), ""); +} diff --git a/test/std/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp new file mode 100644 index 0000000000000..0ee1e8c93a674 --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp @@ -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> + +// template <class Ptr> +// struct pointer_traits +// { +// typedef <details> element_type; +// ... +// }; + +#include <memory> +#include <type_traits> + +struct A +{ + typedef char element_type; +}; + +template <class T> +struct B +{ + typedef char element_type; +}; + +template <class T> +struct C +{ +}; + +template <class T, class U> +struct D +{ +}; + +int main() +{ + static_assert((std::is_same<std::pointer_traits<A>::element_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::element_type, char>::value), ""); + static_assert((std::is_same<std::pointer_traits<C<int> >::element_type, int>::value), ""); + static_assert((std::is_same<std::pointer_traits<D<double, int> >::element_type, double>::value), ""); +} diff --git a/test/std/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp new file mode 100644 index 0000000000000..4a1455c53ef6f --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class Ptr> +// struct pointer_traits +// { +// template <class U> using rebind = <details>; +// ... +// }; + +#include <memory> +#include <type_traits> + +template <class T> +struct A +{ +}; + +template <class T> struct B1 {}; + +template <class T> +struct B +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + template <class U> using rebind = B1<U>; +#else + template <class U> struct rebind {typedef B1<U> other;}; +#endif +}; + +template <class T, class U> +struct C +{ +}; + +template <class T, class U> struct D1 {}; + +template <class T, class U> +struct D +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + template <class V> using rebind = D1<V, U>; +#else + template <class V> struct rebind {typedef D1<V, U> other;}; +#endif +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), ""); + static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), ""); + static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), ""); +#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), ""); + static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), ""); + static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), ""); + static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), ""); +#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} diff --git a/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp b/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp new file mode 100644 index 0000000000000..fc44d9d77a2f8 --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// static pointer pointer_to(<details>); +// ... +// }; + +#include <memory> +#include <cassert> + +int main() +{ + { + int i = 0; + int* a = std::pointer_traits<int*>::pointer_to(i); + assert(a == &i); + } + { + (std::pointer_traits<void*>::element_type)0; + } +} diff --git a/test/std/utilities/memory/pointer.traits/rebind.pass.cpp b/test/std/utilities/memory/pointer.traits/rebind.pass.cpp new file mode 100644 index 0000000000000..8716c05f3335a --- /dev/null +++ b/test/std/utilities/memory/pointer.traits/rebind.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct pointer_traits<T*> +// { +// template <class U> using rebind = U*; +// ... +// }; + +#include <memory> +#include <type_traits> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>, double*>::value), ""); +#else + static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>::other, double*>::value), ""); +#endif +} diff --git a/test/std/utilities/memory/ptr.align/align.pass.cpp b/test/std/utilities/memory/ptr.align/align.pass.cpp new file mode 100644 index 0000000000000..d77d13c906de7 --- /dev/null +++ b/test/std/utilities/memory/ptr.align/align.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// #include <memory> + +// void* align(size_t alignment, size_t size, void*& ptr, size_t& space); + +#include <memory> +#include <cassert> + +int main() +{ + const unsigned N = 20; + char buf[N]; + void* r; + void* p = &buf[0]; + std::size_t s = N; + r = std::align(4, 10, p, s); + assert(p == &buf[0]); + assert(r == p); + assert(s == N); + + p = &buf[1]; + s = N; + r = std::align(4, 10, p, s); + assert(p == &buf[4]); + assert(r == p); + assert(s == N-3); + + p = &buf[2]; + s = N; + r = std::align(4, 10, p, s); + assert(p == &buf[4]); + assert(r == p); + assert(s == N-2); + + p = &buf[3]; + s = N; + r = std::align(4, 10, p, s); + assert(p == &buf[4]); + assert(r == p); + assert(s == N-1); + + p = &buf[4]; + s = N; + r = std::align(4, 10, p, s); + assert(p == &buf[4]); + assert(r == p); + assert(s == N); + + p = &buf[0]; + s = N; + r = std::align(4, N, p, s); + assert(p == &buf[0]); + assert(r == p); + assert(s == N); + + p = &buf[1]; + s = N-1; + r = std::align(4, N-4, p, s); + assert(p == &buf[4]); + assert(r == p); + assert(s == N-4); + + p = &buf[1]; + s = N-1; + r = std::align(4, N-3, p, s); + assert(p == &buf[1]); + assert(r == nullptr); + assert(s == N-1); + + p = &buf[0]; + s = N; + r = std::align(1, N+1, p, s); + assert(p == &buf[0]); + assert(r == nullptr); + assert(s == N); +} diff --git a/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp b/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp new file mode 100644 index 0000000000000..e07bec4d0a47e --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <ObjectType T> T* addressof(T& r); + +#include <memory> +#include <cassert> + +struct A +{ + void operator&() const {} +}; + +struct nothing { + operator char&() + { + static char c; + return c; + } +}; + +int main() +{ + { + int i; + double d; + assert(std::addressof(i) == &i); + assert(std::addressof(d) == &d); + A* tp = new A; + const A* ctp = tp; + assert(std::addressof(*tp) == tp); + assert(std::addressof(*ctp) == tp); + delete tp; + } + { + union + { + nothing n; + int i; + }; + assert(std::addressof(n) == (void*)std::addressof(i)); + } +} diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp new file mode 100644 index 0000000000000..f431335db732b --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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 InputIterator, class ForwardIterator> +// ForwardIterator +// uninitialized_copy(InputIterator first, InputIterator last, +// ForwardIterator result); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +struct Nasty +{ + Nasty() : i_ ( counter_++ ) {} + Nasty * operator &() const { return NULL; } + int i_; + static int counter_; +}; + +int Nasty::counter_ = 0; + +int main() +{ + { + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + B b[N]; + try + { + std::uninitialized_copy(b, b+N, bp); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_copy(b, b+2, bp); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); + } + { + const int N = 5; + char pool[sizeof(Nasty)*N] = {0}; + Nasty * p = (Nasty *) pool; + Nasty arr[N]; + std::uninitialized_copy(arr, arr+N, p); + for (int i = 0; i < N; ++i) { + assert(arr[i].i_ == i); + assert( p[i].i_ == i); + } + } + +} diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp new file mode 100644 index 0000000000000..3b2007b969c3f --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class InputIterator, class Size, class ForwardIterator> +// ForwardIterator +// uninitialized_copy_n(InputIterator first, Size n, +// ForwardIterator result); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +struct Nasty +{ + Nasty() : i_ ( counter_++ ) {} + Nasty * operator &() const { return NULL; } + int i_; + static int counter_; +}; + +int Nasty::counter_ = 0; + +int main() +{ + { + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + B b[N]; + try + { + std::uninitialized_copy_n(b, 5, bp); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_copy_n(b, 2, bp); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); + } + { + const int N = 5; + char pool[sizeof(Nasty)*N] = {0}; + Nasty * p = (Nasty *) pool; + Nasty arr[N]; + std::uninitialized_copy_n(arr, N, p); + for (int i = 0; i < N; ++i) { + assert(arr[i].i_ == i); + assert( p[i].i_ == i); + } + } +} diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp new file mode 100644 index 0000000000000..d2b1dfa288686 --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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 ForwardIterator, class Size, class T> +// ForwardIterator +// uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +struct Nasty +{ + Nasty() : i_ ( counter_++ ) {} + Nasty * operator &() const { return NULL; } + int i_; + static int counter_; +}; + +int Nasty::counter_ = 0; + +int main() +{ + { + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + try + { + std::uninitialized_fill_n(bp, 5, B()); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + B* r = std::uninitialized_fill_n(bp, 2, B()); + assert(r == bp + 2); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); + } + { + { + const int N = 5; + char pool[N*sizeof(Nasty)] = {0}; + Nasty* bp = (Nasty*)pool; + + Nasty::counter_ = 23; + std::uninitialized_fill_n(bp, N, Nasty()); + for (int i = 0; i < N; ++i) + assert(bp[i].i_ == 23); + } + + } +} diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp new file mode 100644 index 0000000000000..47cabdfa478a6 --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// 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 ForwardIterator, class T> +// void +// uninitialized_fill(ForwardIterator first, ForwardIterator last, +// const T& x); + +#include <memory> +#include <cassert> + +struct B +{ + static int count_; + int data_; + explicit B() : data_(1) {} + B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} + ~B() {data_ = 0;} +}; + +int B::count_ = 0; + +struct Nasty +{ + Nasty() : i_ ( counter_++ ) {} + Nasty * operator &() const { return NULL; } + int i_; + static int counter_; +}; + +int Nasty::counter_ = 0; + +int main() +{ + { + const int N = 5; + char pool[sizeof(B)*N] = {0}; + B* bp = (B*)pool; + try + { + std::uninitialized_fill(bp, bp+N, B()); + assert(false); + } + catch (...) + { + for (int i = 0; i < N; ++i) + assert(bp[i].data_ == 0); + } + B::count_ = 0; + std::uninitialized_fill(bp, bp+2, B()); + for (int i = 0; i < 2; ++i) + assert(bp[i].data_ == 1); + } + { + const int N = 5; + char pool[N*sizeof(Nasty)] = {0}; + Nasty* bp = (Nasty*)pool; + + Nasty::counter_ = 23; + std::uninitialized_fill(bp, bp+N, Nasty()); + for (int i = 0; i < N; ++i) + assert(bp[i].i_ == 23); + } +} diff --git a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp new file mode 100644 index 0000000000000..27b620569b83f --- /dev/null +++ b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// raw_storage_iterator + +#include <memory> +#include <type_traits> +#include <cassert> + +int A_constructed = 0; + +struct A +{ + int data_; +public: + explicit A(int i) : data_(i) {++A_constructed;} + + A(const A& a) : data_(a.data_) {++A_constructed;} + ~A() {--A_constructed; data_ = 0;} + + bool operator==(int i) const {return data_ == i;} +}; + +int main() +{ +#if __cplusplus >= 201402L + typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type + Storage; + Storage buffer; + std::raw_storage_iterator<A*, A> it((A*)&buffer); + assert(A_constructed == 0); + assert(it.base() == (A*)&buffer); + for (int i = 0; i < 3; ++i) + { + *it++ = A(i+1); + A* ap = (A*)&buffer + i; + assert(*ap == i+1); + assert(A_constructed == i+1); + assert(it.base() == ap + 1); // next place to write + } +#endif +} diff --git a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp new file mode 100644 index 0000000000000..f77d6c75e17a4 --- /dev/null +++ b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// raw_storage_iterator + +#include <memory> +#include <type_traits> +#include <cassert> + +int A_constructed = 0; + +struct A +{ + int data_; +public: + explicit A(int i) : data_(i) {++A_constructed;} + + A(const A& a) : data_(a.data_) {++A_constructed;} + ~A() {--A_constructed; data_ = 0;} + + bool operator==(int i) const {return data_ == i;} +}; + +int main() +{ + typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type + Storage; + Storage buffer; + std::raw_storage_iterator<A*, A> it((A*)&buffer); + assert(A_constructed == 0); + for (int i = 0; i < 3; ++i) + { + *it++ = A(i+1); + A* ap = (A*)&buffer + i; + assert(*ap == i+1); + assert(A_constructed == i+1); + } +} diff --git a/test/std/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp b/test/std/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp new file mode 100644 index 0000000000000..c1575bda2bac6 --- /dev/null +++ b/test/std/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// pair<T*, ptrdiff_t> +// get_temporary_buffer(ptrdiff_t n); +// +// template <class T> +// void +// return_temporary_buffer(T* p); + +#include <memory> +#include <cassert> + +int main() +{ + std::pair<int*, std::ptrdiff_t> ip = std::get_temporary_buffer<int>(5); + assert(ip.first); + assert(ip.second == 5); + std::return_temporary_buffer(ip.first); +} diff --git a/test/std/utilities/memory/unique.ptr/deleter.h b/test/std/utilities/memory/unique.ptr/deleter.h new file mode 100644 index 0000000000000..fb26044d98ff6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/deleter.h @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Example move-only deleter + +#ifndef DELETER_H +#define DELETER_H + +#include <type_traits> +#include <utility> +#include <cassert> + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(0) {} + explicit Deleter(int s) : state_(s) {} + ~Deleter() {assert(state_ >= 0); state_ = -1;} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +template <class T> +class Deleter<T[]> +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(0) {} + explicit Deleter(int s) : state_(s) {} + ~Deleter() {assert(state_ >= 0); state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete [] p;} +}; + +template <class T> +void +swap(Deleter<T>& x, Deleter<T>& y) +{ + Deleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +template <class T> +class CDeleter +{ + int state_; + +public: + + CDeleter() : state_(0) {} + explicit CDeleter(int s) : state_(s) {} + ~CDeleter() {assert(state_ >= 0); state_ = -1;} + + template <class U> + CDeleter(const CDeleter<U>& d) + : state_(d.state()) {} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +template <class T> +class CDeleter<T[]> +{ + int state_; + +public: + + CDeleter() : state_(0) {} + explicit CDeleter(int s) : state_(s) {} + ~CDeleter() {assert(state_ >= 0); state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete [] p;} +}; + +template <class T> +void +swap(CDeleter<T>& x, CDeleter<T>& y) +{ + CDeleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +#endif // DELETER_H diff --git a/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp b/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp new file mode 100644 index 0000000000000..b2fb58f529f31 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +#include <memory> +#include <string> +#include <cassert> + +// The only way to create an unique_ptr<T[]> is to default construct them. + +class foo { +public: + foo () : val_(3) {} + int get () const { return val_; } +private: + int val_; + }; + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + auto p1 = std::make_unique<int[]>(5); + for ( int i = 0; i < 5; ++i ) + assert ( p1[i] == 0 ); + } + + { + auto p2 = std::make_unique<std::string[]>(5); + for ( int i = 0; i < 5; ++i ) + assert ( p2[i].size () == 0 ); + } + + { + auto p3 = std::make_unique<foo[]>(7); + for ( int i = 0; i < 7; ++i ) + assert ( p3[i].get () == 3 ); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp new file mode 100644 index 0000000000000..00987919413bb --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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 <string> +#include <cassert> + +int main() +{ + auto up1 = std::make_unique<std::string[]>("error"); // doesn't compile - no bound +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp new file mode 100644 index 0000000000000..cc94e9ab3aaab --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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 <string> +#include <cassert> + +int main() +{ + auto up2 = std::make_unique<int[]>(10, 20, 30, 40); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp new file mode 100644 index 0000000000000..cfdc2e1d886b0 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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 <string> +#include <cassert> + +int main() +{ + auto up3 = std::make_unique<int[5]>(); // this is deleted +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp new file mode 100644 index 0000000000000..26eb59bbfd711 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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 <string> +#include <cassert> + +int main() +{ + auto up4 = std::make_unique<int[5]>(11, 22, 33, 44, 55); // deleted +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp new file mode 100644 index 0000000000000..7326ed226557c --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 <string> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + std::unique_ptr<int> p1 = std::make_unique<int>(1); + assert ( *p1 == 1 ); + p1 = std::make_unique<int> (); + assert ( *p1 == 0 ); + } + + { + std::unique_ptr<std::string> p2 = std::make_unique<std::string> ( "Meow!" ); + assert ( *p2 == "Meow!" ); + p2 = std::make_unique<std::string> (); + assert ( *p2 == "" ); + p2 = std::make_unique<std::string> ( 6, 'z' ); + assert ( *p2 == "zzzzzz" ); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp new file mode 100644 index 0000000000000..9bf794caeda27 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + std::default_delete<B> d2; + std::default_delete<A> d1 = d2; + A* p = new B; + assert(A::count == 1); + assert(B::count == 1); + d1(p); + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp new file mode 100644 index 0000000000000..f686e9f01f113 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// default_delete + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + std::default_delete<A> d; + A* p = new A; + assert(A::count == 1); + d(p); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp new file mode 100644 index 0000000000000..255e5cd39c69b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// default_delete + +// Test that default_delete's operator() requires a complete type + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::default_delete<A> d; + A* p = 0; + d(p); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp new file mode 100644 index 0000000000000..5d1cf1ff4981e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// default_delete + +// Test that default_delete's operator() requires a complete type + +#include <memory> +#include <cassert> + +int main() +{ + std::default_delete<const void> d; + const void* p = 0; + d(p); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp new file mode 100644 index 0000000000000..41209d977b71e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// default_delete + +// Test that default_delete<T[]> does not have a working converting constructor + +#include <memory> +#include <cassert> + +struct A +{ +}; + +struct B + : public A +{ +}; + +int main() +{ + std::default_delete<B[]> d2; + std::default_delete<A[]> d1 = d2; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp new file mode 100644 index 0000000000000..7a409766412fd --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp @@ -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> + +// default_delete + +// Test that default_delete<T[]> has a working default constructor + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + std::default_delete<A[]> d; + A* p = new A[3]; + assert(A::count == 3); + d(p); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp new file mode 100644 index 0000000000000..528b10e9085d6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// default_delete + +// Test that default_delete<T[]>'s operator() requires a complete type + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::default_delete<A[]> d; + A* p = 0; + d(p); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp new file mode 100644 index 0000000000000..17375ede00f59 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp @@ -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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp new file mode 100644 index 0000000000000..286e6bc9a7b91 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s1(new A[3]); + A* p = s1.get(); + assert(A::count == 3); + std::unique_ptr<A[]> s2(new A[2]); + assert(A::count == 5); + s2 = std::move(s1); + assert(A::count == 3); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5)); + A* p = s1.get(); + assert(A::count == 4); + std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]); + assert(A::count == 9); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 4); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter<A[]> d1(5); + std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1); + A* p = s1.get(); + assert(A::count == 6); + CDeleter<A[]> d2(6); + std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2); + assert(A::count == 9); + s2 = std::move(s1); + assert(A::count == 6); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp new file mode 100644 index 0000000000000..6e13873c2fb3b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp @@ -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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A[]> s(new A[3]); + std::unique_ptr<A[]> s2; + s2 = s; + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp new file mode 100644 index 0000000000000..3712a27963929 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp new file mode 100644 index 0000000000000..4e85e5b0fb906 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp new file mode 100644 index 0000000000000..9461958a431dd --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp new file mode 100644 index 0000000000000..1737136f4d72a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp new file mode 100644 index 0000000000000..3c89bb12344eb --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp new file mode 100644 index 0000000000000..970beb5a150e9 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't assign from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const boost::unique_ptr<B[]> s(new B); + A* p = s.get(); + boost::unique_ptr<A[]> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp new file mode 100644 index 0000000000000..786858dd40169 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp new file mode 100644 index 0000000000000..46d4c0985d716 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + const boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp new file mode 100644 index 0000000000000..65ee2694156f6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[]> s(new B); + A* p = s.get(); + boost::unique_ptr<A[]> s2(new A); + assert(A::count == 2); + s2 = boost::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp new file mode 100644 index 0000000000000..da08195ffdd3a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + boost::unique_ptr<B[], Deleter<B> > s(new B); + A* p = s.get(); + boost::unique_ptr<A[], Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = (boost::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp new file mode 100644 index 0000000000000..aeec076cb86ab --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// test converting move assignment with reference deleters + +#include <memory> +#include <utility> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + boost::unique_ptr<B[], Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + boost::unique_ptr<A[], Deleter<A>&> s2(new A, da); + s2 = boost::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp new file mode 100644 index 0000000000000..e2d7956cda643 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = 0; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp new file mode 100644 index 0000000000000..6d752b9951a57 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// The deleter is not called if get() == 0 + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(0) {} + + int state() const {return state_;} + + void operator()(void*) {++state_;} +}; + +int main() +{ + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr<int[], Deleter&> p(0, d); + assert(p.get() == 0); + assert(&p.get_deleter() == &d); + } + assert(d.state() == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp new file mode 100644 index 0000000000000..30ecdded3cf7b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s2(new A[3]); + assert(A::count == 3); + s2 = nullptr; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp new file mode 100644 index 0000000000000..e7ad6ad7ef33d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr<T[]>::pointer type + +#include <memory> +#include <type_traits> + +struct Deleter +{ + struct pointer {}; +}; + +int main() +{ + { + typedef std::unique_ptr<int[]> P; + static_assert((std::is_same<P::pointer, int*>::value), ""); + } + { + typedef std::unique_ptr<int[], Deleter> P; + static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp new file mode 100644 index 0000000000000..b6bcad9a91c66 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require default Deleter ctor + + +#include <memory> + +class Deleter +{ + // expected-error@memory:* {{base class 'Deleter' has private default constructor}} + // expected-note@memory:* + {{in instantiation of member function}} + Deleter() {} // expected-note {{implicitly declared private here}} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) { return *this; } + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp new file mode 100644 index 0000000000000..0cc54382b98df --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should only require default Deleter ctor + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int[]> p; + assert(p.get() == 0); + } + { + std::unique_ptr<int[], Deleter> p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp new file mode 100644 index 0000000000000..82b84948f3f0d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require non-reference Deleter ctor + +#include <memory> + +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter&> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp new file mode 100644 index 0000000000000..3ded41c419c88 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test default unique_ptr<T[]> ctor + +// default unique_ptr<T[]> ctor shouldn't require complete type + +#include <memory> +#include <cassert> + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A[], D> a_; + B(); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +int main() +{ + { + B<> s; + assert(s.get() == 0); + } + check(0); + { + B<Deleter> s; + assert(s.get() == 0); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B() {} + +template <class D> +B<D>::~B() {} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp new file mode 100644 index 0000000000000..74d24fd488b65 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +// default unique_ptr ctor should require non-pointer Deleter + +#include <memory> + +int main() +{ + std::unique_ptr<int[], void (*)(void*)> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp new file mode 100644 index 0000000000000..bc49a0e5c31e1 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp new file mode 100644 index 0000000000000..03747b4f89cf6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class NCDeleter +{ + int state_; + + NCDeleter(NCDeleter&); + NCDeleter& operator=(NCDeleter&); +public: + + NCDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + } + assert(A::count == 0); + { + std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5)); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + NCDeleter d; + std::unique_ptr<A[], NCDeleter&> s(new A[3], d); + A* p = s.get(); + std::unique_ptr<A[], NCDeleter&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 3); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp new file mode 100644 index 0000000000000..8e44c78bf1e94 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from const lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A[]> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp new file mode 100644 index 0000000000000..ef821a915e449 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class NCDeleter +{ + int state_; + + NCDeleter(NCDeleter&); + NCDeleter& operator=(NCDeleter&); +public: + + NCDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +std::unique_ptr<A[]> +source1() +{ + return std::unique_ptr<A[]>(new A[3]); +} + +void sink1(std::unique_ptr<A[]> p) +{ +} + +std::unique_ptr<A[], Deleter<A[]> > +source2() +{ + return std::unique_ptr<A[], Deleter<A[]> >(new A[3]); +} + +void sink2(std::unique_ptr<A[], Deleter<A[]> > p) +{ +} + +std::unique_ptr<A[], NCDeleter&> +source3() +{ + static NCDeleter d; + return std::unique_ptr<A[], NCDeleter&>(new A[3], d); +} + +void sink3(std::unique_ptr<A[], NCDeleter&> p) +{ +} + +int main() +{ + sink1(source1()); + sink2(source2()); + sink3(source3()); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp new file mode 100644 index 0000000000000..c952cf2d4e13c --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + std::unique_ptr<A[], Deleter> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[], Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp new file mode 100644 index 0000000000000..0d091ff346d12 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +// test move ctor. Can't copy from const lvalue + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + const std::unique_ptr<A[], Deleter> s(new A[3]); + A* p = s.get(); + std::unique_ptr<A[], Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp new file mode 100644 index 0000000000000..d175fbf93adc5 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp new file mode 100644 index 0000000000000..1838511b49297 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp new file mode 100644 index 0000000000000..36ad75d8331a5 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp new file mode 100644 index 0000000000000..3a19bde928890 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp new file mode 100644 index 0000000000000..bda2a70a4ef30 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp new file mode 100644 index 0000000000000..fba895137b05f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp new file mode 100644 index 0000000000000..24c646988f0a3 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp new file mode 100644 index 0000000000000..486d90825d9ef --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp new file mode 100644 index 0000000000000..e4cbef5c05606 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp new file mode 100644 index 0000000000000..73423d1b3751f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp new file mode 100644 index 0000000000000..cfc097ba0b841 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp new file mode 100644 index 0000000000000..fdb088250b9fe --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp new file mode 100644 index 0000000000000..d9ef8e96fe8fc --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp new file mode 100644 index 0000000000000..b4577a126c68a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp new file mode 100644 index 0000000000000..9325d07d0d0c1 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp new file mode 100644 index 0000000000000..b090e593ec62d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[]> s(new B); + A* p = s.get(); + std::unique_ptr<A[]> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp new file mode 100644 index 0000000000000..b2af3c7a69385 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B[], Deleter<B[]> > s(new B); + A* p = s.get(); + std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp new file mode 100644 index 0000000000000..d1c0e8a781e67 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B[], CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp new file mode 100644 index 0000000000000..9a8c17547bca8 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int[]> p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr<int[], Deleter> p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp new file mode 100644 index 0000000000000..4c31611508315 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp @@ -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> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor + +#include <memory> + +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp new file mode 100644 index 0000000000000..dab42f277411b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[]> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp new file mode 100644 index 0000000000000..af7f27f73fc59 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +#include <memory> + +// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int[], Deleter&> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp new file mode 100644 index 0000000000000..1afb1c32ce8c4 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor shouldn't require complete type + +#include <memory> +#include <cassert> + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A[]> > +struct B +{ + std::unique_ptr<A[], D> a_; + explicit B(A*); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +A* get(); + +int main() +{ + { + A* p = get(); + check(3); + B<> s(p); + assert(s.get() == p); + } + check(0); + { + A* p = get(); + check(3); + B<Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +A* get() {return new A[3];} + +void Deleter::operator()(A* p) {delete [] p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B(A* a) : a_(a) {} + +template <class D> +B<D>::~B() {} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp new file mode 100644 index 0000000000000..31f7ce367e3dc --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr<T[]>(pointer) ctor + +// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter + +#include <memory> + +int main() +{ + std::unique_ptr<int[], void (*)(void*)> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp new file mode 100644 index 0000000000000..591144f7aa588 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +// unique_ptr(pointer) ctor should not work with derived pointers + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + B* p = new B[3]; + std::unique_ptr<A[]> s(p); + } + { + B* p = new B[3]; + std::unique_ptr<A[], Deleter> s(p); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp new file mode 100644 index 0000000000000..2d62bccdce501 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>()); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp new file mode 100644 index 0000000000000..914076b50f428 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, d) requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], Deleter> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp new file mode 100644 index 0000000000000..a6f535f38f088 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp new file mode 100644 index 0000000000000..b635d507b2ecb --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T, const D&>(pointer, D()) should not compile + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + std::unique_ptr<A[], const Deleter&> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp new file mode 100644 index 0000000000000..a4c917c1af76c --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete [] p;} +}; + +int main() +{ + { + A* p = new A[3]; + assert(A::count == 3); + Deleter d; + std::unique_ptr<A[], const Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp new file mode 100644 index 0000000000000..0e03a7da07fb6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +// unique_ptr(pointer, deleter) should not work with derived pointers + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete [] p;} +}; + +int main() +{ + B* p = new B[3]; + std::unique_ptr<A[], Deleter> s(p, Deleter()); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp new file mode 100644 index 0000000000000..d79a4e396eeda --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp @@ -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> + +// unique_ptr + +// test release + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int[]> p(new int[3]); + int* i = p.get(); + int* j = p.release(); + assert(p.get() == 0); + assert(i == j); + delete [] j; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp new file mode 100644 index 0000000000000..195d877bbb700 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> p(new A[3]); + assert(A::count == 3); + A* i = p.get(); + assert(i != nullptr); + p.reset(); + assert(A::count == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A[]> p(new A[4]); + assert(A::count == 4); + A* i = p.get(); + assert(i != nullptr); + p.reset(new A[5]); + assert(A::count == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp new file mode 100644 index 0000000000000..bca6cb2470ac4 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<A[]> p(new A); + assert(A::count == 1); + assert(B::count == 0); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + std::unique_ptr<A[]> p(new B); + assert(A::count == 1); + assert(B::count == 1); + A* i = p.get(); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp new file mode 100644 index 0000000000000..e9754cc0f2266 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test swap + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + int state_; + static int count; + A() : state_(0) {++count;} + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1)); + A* p2 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2)); + assert(s1.get() == p1); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(s2.get_deleter().state() == 1); + assert(A::count == 6); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp new file mode 100644 index 0000000000000..46ba1395bb857 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int[]> p(new int(3)); + assert(*p == 3); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp new file mode 100644 index 0000000000000..9ec9b9527e8ab --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp @@ -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> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + { + std::unique_ptr<int[]> p(new int [3]); + if (p) + ; + else + assert(false); + if (!p) + assert(false); + } + { + std::unique_ptr<int[]> p; + if (!p) + ; + else + assert(false); + if (p) + assert(false); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp new file mode 100644 index 0000000000000..2ae0659adc260 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test get + +#include <memory> +#include <cassert> + +int main() +{ + int* p = new int[3]; + std::unique_ptr<int[]> s(p); + assert(s.get() == p); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp new file mode 100644 index 0000000000000..4496740715a51 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test get_deleter() + +#include <memory> +#include <cassert> + +struct Deleter +{ + void operator()(void*) {} + + int test() {return 5;} + int test() const {return 6;} +}; + +int main() +{ + { + std::unique_ptr<int[], Deleter> p; + assert(p.get_deleter().test() == 5); + } + { + const std::unique_ptr<int[], Deleter> p; + assert(p.get_deleter().test() == 6); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp new file mode 100644 index 0000000000000..519eae688ec1b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op[](size_t) + +#include <memory> +#include <cassert> + +class A +{ + int state_; + static int next_; +public: + A() : state_(++next_) {} + int get() const {return state_;} + + friend bool operator==(const A& x, int y) + {return x.state_ == y;} + + A& operator=(int i) {state_ = i; return *this;} +}; + +int A::next_ = 0; + +int main() +{ + std::unique_ptr<A[]> p(new A[3]); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3); + p[0] = 3; + p[1] = 2; + p[2] = 1; + assert(p[0] == 3); + assert(p[1] == 2); + assert(p[2] == 1); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp new file mode 100644 index 0000000000000..1c90ba76af393 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op->() + +#include <memory> +#include <cassert> + +struct A +{ + int i_; + + A() : i_(7) {} +}; + +int main() +{ + std::unique_ptr<A[]> p(new A); + assert(p->i_ == 7); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp new file mode 100644 index 0000000000000..8721062c6d025 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr::pointer type + +#include <memory> +#include <type_traits> + +struct Deleter +{ + struct pointer {}; +}; + +int main() +{ + { + typedef std::unique_ptr<int> P; + static_assert((std::is_same<P::pointer, int*>::value), ""); + } + { + typedef std::unique_ptr<int, Deleter> P; + static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp new file mode 100644 index 0000000000000..57724ae10a70a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp new file mode 100644 index 0000000000000..9535ed0295d46 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s1(new A); + A* p = s1.get(); + std::unique_ptr<A> s2(new A); + assert(A::count == 2); + s2 = std::move(s1); + assert(A::count == 1); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5)); + A* p = s1.get(); + std::unique_ptr<A, Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter<A> d1(5); + std::unique_ptr<A, CDeleter<A>&> s1(new A, d1); + A* p = s1.get(); + CDeleter<A> d2(6); + std::unique_ptr<A, CDeleter<A>&> s2(new A, d2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == 1); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp new file mode 100644 index 0000000000000..5046fd8aae6b3 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A> s(new A); + std::unique_ptr<A> s2; + s2 = s; + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp new file mode 100644 index 0000000000000..aa4fdb8a96b1d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp new file mode 100644 index 0000000000000..e0d7c891c80f6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp new file mode 100644 index 0000000000000..3fd2cbc42bd60 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp new file mode 100644 index 0000000000000..989f594e38b8e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(new A); + assert(A::count == 2); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp new file mode 100644 index 0000000000000..0f900603e2390 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +// Can't assign from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp new file mode 100644 index 0000000000000..a448c77a66a7f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(new A); + assert(A::count == 2); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp new file mode 100644 index 0000000000000..f35af9f453ff0 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + std::unique_ptr<B, Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + std::unique_ptr<A, Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp new file mode 100644 index 0000000000000..9aea81a8b1444 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// test converting move assignment with reference deleters + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + CDeleter<B> db(5); + std::unique_ptr<B, CDeleter<B>&> s(new B, db); + A* p = s.get(); + CDeleter<A> da(6); + std::unique_ptr<A, CDeleter<A>&> s2(new A, da); + s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s.get_deleter().state() == 5); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp new file mode 100644 index 0000000000000..dba901b2ce176 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +// Can't assign from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp new file mode 100644 index 0000000000000..4694986c67730 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2; + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp new file mode 100644 index 0000000000000..220677cd6fa77 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Can't assign from const lvalue + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + Deleter<B> db(5); + const std::unique_ptr<B, Deleter<B>&> s(new B, db); + A* p = s.get(); + Deleter<A> da(6); + std::unique_ptr<A, Deleter<A>&> s2(new A, da); + s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp new file mode 100644 index 0000000000000..56ab43c7de246 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp @@ -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> + +// unique_ptr + +// Test unique_ptr converting move assignment + +// Do not convert from an array unique_ptr + +#include <memory> +#include <utility> +#include <cassert> + +struct A +{ +}; + +struct Deleter +{ + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<A[], Deleter> s; + std::unique_ptr<A, Deleter> s2; + s2 = std::move(s); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp new file mode 100644 index 0000000000000..e2d7956cda643 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = 0; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp new file mode 100644 index 0000000000000..fb15849519938 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move assignment + +#include <memory> +#include <cassert> + +// test assignment from null + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s2(new A); + assert(A::count == 1); + s2 = nullptr; + assert(A::count == 0); + assert(s2.get() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp new file mode 100644 index 0000000000000..1ce1838afbb7e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <utility> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up(std::move(ap)); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up; + up = std::move(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp new file mode 100644 index 0000000000000..1f317c7824542 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B +// : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A> up; + up = ap; + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp new file mode 100644 index 0000000000000..2dd5ea30049b8 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// template <class U> explicit unique_ptr(auto_ptr<U>&); + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct Deleter +{ + template <class T> + void operator()(T*) {} +}; + +int main() +{ + { + B* p = new B; + std::auto_ptr<B> ap(p); + std::unique_ptr<A, Deleter> up(ap); + assert(up.get() == p); + assert(ap.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp new file mode 100644 index 0000000000000..2ffe1be190e0b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require default Deleter ctor +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int, Deleter> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp new file mode 100644 index 0000000000000..e63db5cb71853 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int> p; + assert(p.get() == 0); + } + { + std::unique_ptr<int, Deleter> p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp new file mode 100644 index 0000000000000..690750143414b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int, Deleter&> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp new file mode 100644 index 0000000000000..e9af7e285255b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test default unique_ptr ctor + +#include <memory> +#include <cassert> + +// default unique_ptr ctor shouldn't require complete type + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A, D> a_; + B() {} + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +int main() +{ + { + B<> s; + assert(s.get() == 0); + } + check(0); + { + B<Deleter> s; + assert(s.get() == 0); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::~B() {} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp new file mode 100644 index 0000000000000..78f6e73a1d55c --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr default ctor + +#include <memory> + +// default unique_ptr ctor should require non-pointer Deleter + +int main() +{ + std::unique_ptr<int, void (*)(void*)> p; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp new file mode 100644 index 0000000000000..68ad589b11480 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp new file mode 100644 index 0000000000000..dc16c3115376e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp @@ -0,0 +1,142 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(5) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::unique_ptr<A, Deleter<A> > s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter d; + std::unique_ptr<A, CDeleter&> s(new A, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp new file mode 100644 index 0000000000000..897b889d67789 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp new file mode 100644 index 0000000000000..4b997df95a0b1 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp @@ -0,0 +1,143 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(5) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +std::unique_ptr<A> +source1() +{ + return std::unique_ptr<A>(new A); +} + +void sink1(std::unique_ptr<A> p) +{ +} + +std::unique_ptr<A, Deleter<A> > +source2() +{ + return std::unique_ptr<A, Deleter<A> >(new A); +} + +void sink2(std::unique_ptr<A, Deleter<A> > p) +{ +} + +std::unique_ptr<A, CDeleter&> +source3() +{ + static CDeleter d; + return std::unique_ptr<A, CDeleter&>(new A, d); +} + +void sink3(std::unique_ptr<A, CDeleter&> p) +{ +} + +int main() +{ + sink1(source1()); + sink2(source2()); + sink3(source3()); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp new file mode 100644 index 0000000000000..7fb1a0a748114 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp new file mode 100644 index 0000000000000..671e343fd7f5d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <cassert> + +// test move ctor. Can't copy from const lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<A, Deleter> s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp new file mode 100644 index 0000000000000..ed1fe8c2bdd4b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// Can't construct from lvalue + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp new file mode 100644 index 0000000000000..b65cf564a925c --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp new file mode 100644 index 0000000000000..a1bf634b9995e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp new file mode 100644 index 0000000000000..829e7553acd96 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp new file mode 100644 index 0000000000000..7409199791b56 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp new file mode 100644 index 0000000000000..792076a952450 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(std::move(s)); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp new file mode 100644 index 0000000000000..981ea706eb293 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp new file mode 100644 index 0000000000000..12ab17fadcd34 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp new file mode 100644 index 0000000000000..d055b80627f91 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + std::unique_ptr<B, Deleter<B> > s(new B); + std::unique_ptr<A, Deleter<A> > s2 = s; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp new file mode 100644 index 0000000000000..8077b0dacb232 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(5)); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp new file mode 100644 index 0000000000000..5b9b12e0d60ba --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp new file mode 100644 index 0000000000000..4115107b85f9f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp new file mode 100644 index 0000000000000..bef022cfc1434 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp new file mode 100644 index 0000000000000..978cb0e9024b9 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +#include "../../deleter.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + CDeleter<B> b(5); + std::unique_ptr<B, CDeleter<B>&> s(new B, b); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp new file mode 100644 index 0000000000000..e14bba0763c58 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(5) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp new file mode 100644 index 0000000000000..a475c17547c92 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp new file mode 100644 index 0000000000000..f0da5efb69174 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<B> s(new B); + A* p = s.get(); + std::unique_ptr<A> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp new file mode 100644 index 0000000000000..bcf94a978144b --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Implicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(5) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + const std::unique_ptr<B, Deleter<B> > s(new B); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp new file mode 100644 index 0000000000000..095bec65669b3 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <utility> +#include <cassert> + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +template <class T> +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + CDeleter<A> d; + const std::unique_ptr<B, CDeleter<A>&> s(new B, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter<A>&> s2 = s; + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(B::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp new file mode 100644 index 0000000000000..a4bd2cba1cef8 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// Do not convert from an array unique_ptr + +#include <memory> +#include <utility> +#include <cassert> + +struct A +{ +}; + +struct Deleter +{ + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<A[], Deleter> s; + std::unique_ptr<A, Deleter> s2(std::move(s)); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp new file mode 100644 index 0000000000000..67a48a3e7a12f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include <memory> +#include <cassert> + +// default unique_ptr ctor should only require default Deleter ctor +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(void*) {} +}; + +int main() +{ + { + std::unique_ptr<int> p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr<int, Deleter> p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp new file mode 100644 index 0000000000000..1af04b2c00338 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require default Deleter ctor +class Deleter +{ + + Deleter() {} + +public: + + Deleter(Deleter&) {} + Deleter& operator=(Deleter&) {} + + void operator()(void*) const {} +}; + +int main() +{ + std::unique_ptr<int, Deleter> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp new file mode 100644 index 0000000000000..e5fff774b7909 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor should only require default Deleter ctor + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp new file mode 100644 index 0000000000000..9b7dd8c70f280 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require non-reference Deleter ctor +class Deleter +{ +public: + + void operator()(void*) {} +}; + +int main() +{ + std::unique_ptr<int, Deleter&> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp new file mode 100644 index 0000000000000..a226e87d64a4e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor shouldn't require complete type + +struct A; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p); +}; + +void check(int i); + +template <class D = std::default_delete<A> > +struct B +{ + std::unique_ptr<A, D> a_; + explicit B(A*); + ~B(); + + A* get() const {return a_.get();} + D& get_deleter() {return a_.get_deleter();} +}; + +A* get(); + +int main() +{ + { + A* p = get(); + check(1); + B<> s(p); + assert(s.get() == p); + } + check(0); + { + A* p = get(); + check(1); + B<Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + check(0); +} + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +A* get() {return new A;} + +void Deleter::operator()(A* p) {delete p;} + +void check(int i) +{ + assert(A::count == i); +} + +template <class D> +B<D>::B(A* a) : a_(a) {} + +template <class D> +B<D>::~B() {} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp new file mode 100644 index 0000000000000..a917d87eeeded --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> + +// unique_ptr(pointer) ctor should require non-pointer Deleter + +int main() +{ + std::unique_ptr<int, void (*)(void*)> p(new int); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp new file mode 100644 index 0000000000000..42fc09453914a --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer) ctor should work with derived pointers + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, Deleter> s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp new file mode 100644 index 0000000000000..130f91d6216f5 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +template <class T> +class Deleter +{ + int state_; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} + Deleter& operator=(Deleter&& r) + { + state_ = r.state_; + r.state_ = 0; + return *this; + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + Deleter() : state_(5) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U>&& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {d.set_state(0);} + +private: + template <class U> + Deleter(const Deleter<U>& d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp new file mode 100644 index 0000000000000..421bec55f99c6 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, d) requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, Deleter> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp new file mode 100644 index 0000000000000..bce79dbb1a978 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, D&>(pointer, d) does not requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp new file mode 100644 index 0000000000000..7cacd1fda9f39 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, const D&>(pointer, D()) should not compile + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, const Deleter&> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp new file mode 100644 index 0000000000000..a7750fcb9f0fd --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +// unique_ptr<T, const D&>(pointer, d) does not requires CopyConstructible deleter + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +class Deleter +{ + int state_; + + Deleter(const Deleter&); + Deleter& operator=(const Deleter&); +public: + + Deleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) const {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + Deleter d; + std::unique_ptr<A, const Deleter&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp new file mode 100644 index 0000000000000..1a83258e1e415 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter) should work with derived pointers + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +class Deleter +{ + int state_; + +public: + Deleter() : state_(5) {} + + int state() const {return state_;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, Deleter> s(p, Deleter()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp new file mode 100644 index 0000000000000..ed68052cd3bba --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp @@ -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> + +// unique_ptr + +// Test unique_ptr(pointer, deleter) ctor + +#include <memory> +#include <cassert> + +// unique_ptr(pointer, deleter) should work with function pointers +// unique_ptr<void> should work + +bool my_free_called = false; + +void my_free(void*) +{ + my_free_called = true; +} + +int main() +{ + { + int i = 0; + std::unique_ptr<void, void (*)(void*)> s(&i, my_free); + assert(s.get() == &i); + assert(s.get_deleter() == my_free); + assert(!my_free_called); + } + assert(my_free_called); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp new file mode 100644 index 0000000000000..064f38c5f167f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// The deleter is not called if get() == 0 + +#include <memory> +#include <cassert> + +class Deleter +{ + int state_; + + Deleter(Deleter&); + Deleter& operator=(Deleter&); + +public: + Deleter() : state_(0) {} + + int state() const {return state_;} + + void operator()(void*) {++state_;} +}; + +int main() +{ + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr<int, Deleter&> p(0, d); + assert(p.get() == 0); + assert(&p.get_deleter() == &d); + } + assert(d.state() == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp new file mode 100644 index 0000000000000..dadd4ecbe5901 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp @@ -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> + +// unique_ptr + +// test release + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int> p(new int(3)); + int* i = p.get(); + int* j = p.release(); + assert(p.get() == 0); + assert(i == j); + delete j; +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp new file mode 100644 index 0000000000000..2cf7f8b775683 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + A* i = p.get(); + assert(i != nullptr); + p.reset(); + assert(A::count == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + A* i = p.get(); + assert(i != nullptr); + p.reset(new A); + assert(A::count == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp new file mode 100644 index 0000000000000..2de7787b267e4 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + std::unique_ptr<A> p(new A); + assert(A::count == 1); + assert(B::count == 0); + A* i = p.get(); + assert(i != nullptr); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); + { + std::unique_ptr<A> p(new B); + assert(A::count == 1); + assert(B::count == 1); + A* i = p.get(); + assert(i != nullptr); + p.reset(new B); + assert(A::count == 1); + assert(B::count == 1); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp new file mode 100644 index 0000000000000..58b05efa25f61 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset against resetting self + +#include <memory> + +struct A +{ + std::unique_ptr<A> ptr_; + + A() : ptr_(this) {} + void reset() {ptr_.reset();} +}; + +int main() +{ + (new A)->reset(); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp new file mode 100644 index 0000000000000..d0a03be803269 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test swap + +#include <memory> +#include <cassert> + +#include "../../deleter.h" + +struct A +{ + int state_; + static int count; + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A(1); + std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1)); + A* p2 = new A(2); + std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2)); + assert(s1.get() == p1); + assert(*s1 == A(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2 == A(2)); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(*s1 == A(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2 == A(1)); + assert(s2.get_deleter().state() == 1); + assert(A::count == 2); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp new file mode 100644 index 0000000000000..9d0cfcaaf353d --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + std::unique_ptr<int> p(new int(3)); + assert(*p == 3); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp new file mode 100644 index 0000000000000..d5c7445b0d86f --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp @@ -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> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +int main() +{ + { + std::unique_ptr<int> p(new int(3)); + if (p) + ; + else + assert(false); + if (!p) + assert(false); + } + { + std::unique_ptr<int> p; + if (!p) + ; + else + assert(false); + if (p) + assert(false); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp new file mode 100644 index 0000000000000..24fa6beb42733 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test get + +#include <memory> +#include <cassert> + +int main() +{ + int* p = new int; + std::unique_ptr<int> s(p); + assert(s.get() == p); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp new file mode 100644 index 0000000000000..5ed8a22b14c45 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// test get_deleter() + +#include <memory> +#include <cassert> + +struct Deleter +{ + void operator()(void*) {} + + int test() {return 5;} + int test() const {return 6;} +}; + +int main() +{ + { + std::unique_ptr<int, Deleter> p; + assert(p.get_deleter().test() == 5); + } + { + const std::unique_ptr<int, Deleter> p; + assert(p.get_deleter().test() == 6); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp new file mode 100644 index 0000000000000..21e829cbc4442 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op[](size_t) + +#include <memory> +#include <cassert> + +class A +{ + int state_; + static int next_; +public: + A() : state_(++next_) {} + int get() const {return state_;} + + friend bool operator==(const A& x, int y) + {return x.state_ == y;} + + A& operator=(int i) {state_ = i; return *this;} +}; + +int A::next_ = 0; + +int main() +{ + std::unique_ptr<A> p(new A[3]); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3); + p[0] = 3; + p[1] = 2; + p[2] = 1; + assert(p[0] == 3); + assert(p[1] == 2); + assert(p[2] == 1); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp new file mode 100644 index 0000000000000..47de8f66ed2e4 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op->() + +#include <memory> +#include <cassert> + +struct A +{ + int i_; + + A() : i_(7) {} +}; + +int main() +{ + std::unique_ptr<A> p(new A); + assert(p->i_ == 7); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp new file mode 100644 index 0000000000000..22ae217a61d64 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template <class T, class D> +// bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; +// template <class T, class D> +// bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; +// template <class T, class D> +// bool operator<(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator<(nullptr_t, const unique_ptr<T, D>& y) noexcept; +// template <class T, class D> +// bool operator<=(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator<=(nullptr_t, const unique_ptr<T, D>& y) noexcept; +// template <class T, class D> +// bool operator>(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator>(nullptr_t, const unique_ptr<T, D>& y) noexcept; +// template <class T, class D> +// bool operator>=(const unique_ptr<T, D>& x, nullptr_t) noexcept; +// template <class T, class D> +// bool operator>=(nullptr_t, const unique_ptr<T, D>& y) noexcept; + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + const std::unique_ptr<int> p1(new int(1)); + assert(!(p1 == nullptr)); + assert(!(nullptr == p1)); + assert(!(p1 < nullptr)); + assert( (nullptr < p1)); + assert(!(p1 <= nullptr)); + assert( (nullptr <= p1)); + assert( (p1 > nullptr)); + assert(!(nullptr > p1)); + assert( (p1 >= nullptr)); + assert(!(nullptr >= p1)); + + const std::unique_ptr<int> p2; + assert( (p2 == nullptr)); + assert( (nullptr == p2)); + assert(!(p2 < nullptr)); + assert(!(nullptr < p2)); + assert( (p2 <= nullptr)); + assert( (nullptr <= p2)); + assert(!(p2 > nullptr)); + assert(!(nullptr > p2)); + assert( (p2 >= nullptr)); + assert( (nullptr >= p2)); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp new file mode 100644 index 0000000000000..37886548e7212 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// template <class T1, class D1, class T2, class D2> +// bool +// operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<A, Deleter<A> > p2(new A); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<B, Deleter<B> > p2(new B); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]); + assert(!(p1 == p2)); + assert(p1 != p2); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<A, Deleter<A> > p2; + assert(p1 == p2); + assert(!(p1 != p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<B, Deleter<B> > p2; + assert(p1 == p2); + assert(!(p1 != p2)); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp new file mode 100644 index 0000000000000..80653cf707c3e --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// template <class T1, class D1, class T2, class D2> +// bool +// operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +// template <class T1, class D1, class T2, class D2> +// bool +// operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + static int count; + A() {++count;} + A(const A&) {++count;} + virtual ~A() {--count;} +}; + +int A::count = 0; + +struct B + : public A +{ + static int count; + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +int main() +{ + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<A, Deleter<A> > p2(new A); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1(new A); + const std::unique_ptr<B, Deleter<B> > p2(new B); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]); + const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]); + assert((p1 < p2) == !(p1 > p2)); + assert((p1 < p2) == (p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<A, Deleter<A> > p2; + assert((p1 < p2) == (p1 > p2)); + assert((p1 < p2) == !(p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } + { + const std::unique_ptr<A, Deleter<A> > p1; + const std::unique_ptr<B, Deleter<B> > p2; + assert((p1 < p2) == (p1 > p2)); + assert((p1 < p2) == !(p1 <= p2)); + assert((p1 < p2) == !(p1 >= p2)); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp new file mode 100644 index 0000000000000..44b746fbcfd86 --- /dev/null +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// unique_ptr + +// Test swap + +#include <memory> +#include <cassert> + +#include "../deleter.h" + +struct A +{ + int state_; + static int count; + A() : state_(0) {++count;} + explicit A(int i) : state_(i) {++count;} + A(const A& a) : state_(a.state_) {++count;} + A& operator=(const A& a) {state_ = a.state_; return *this;} + ~A() {--count;} + + friend bool operator==(const A& x, const A& y) + {return x.state_ == y.state_;} +}; + +int A::count = 0; + +int main() +{ + { + A* p1 = new A(1); + std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1)); + A* p2 = new A(2); + std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2)); + assert(s1.get() == p1); + assert(*s1 == A(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2 == A(2)); + assert(s2.get_deleter().state() == 2); + swap(s1, s2); + assert(s1.get() == p2); + assert(*s1 == A(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2 == A(1)); + assert(s2.get_deleter().state() == 1); + assert(A::count == 2); + } + assert(A::count == 0); + { + A* p1 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1)); + A* p2 = new A[3]; + std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2)); + assert(s1.get() == p1); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(s2.get_deleter().state() == 2); + swap(s1, s2); + assert(s1.get() == p2); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(s2.get_deleter().state() == 1); + assert(A::count == 6); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp b/test/std/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp new file mode 100644 index 0000000000000..bbf4be20f8fe7 --- /dev/null +++ b/test/std/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// void declare_no_pointers(char* p, size_t n); +// void undeclare_no_pointers(char* p, size_t n); + +#include <memory> + +int main() +{ + char* p = new char[10]; + std::declare_no_pointers(p, 10); + std::undeclare_no_pointers(p, 10); + delete [] p; +} diff --git a/test/std/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp b/test/std/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp new file mode 100644 index 0000000000000..3f0bcead9bef1 --- /dev/null +++ b/test/std/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// void declare_reachable(void* p); +// template <class T> T* undeclare_reachable(T* p); + +#include <memory> +#include <cassert> + +int main() +{ + int* p = new int; + std::declare_reachable(p); + assert(std::undeclare_reachable(p) == p); + delete p; +} diff --git a/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp b/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp new file mode 100644 index 0000000000000..1f27b45e8ab8e --- /dev/null +++ b/test/std/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// pointer_safety get_pointer_safety(); + +#include <memory> +#include <cassert> + +int main() +{ + std::pointer_safety r = std::get_pointer_safety(); + assert(r == std::pointer_safety::relaxed || + r == std::pointer_safety::preferred || + r == std::pointer_safety::strict); +} diff --git a/test/std/utilities/memory/util.smartptr/nothing_to_do.pass.cpp b/test/std/utilities/memory/util.smartptr/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp new file mode 100644 index 0000000000000..77af13fa90d18 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// template<class T> +// class enable_shared_from_this +// { +// protected: +// enable_shared_from_this(); +// enable_shared_from_this(enable_shared_from_this const&); +// enable_shared_from_this& operator=(enable_shared_from_this const&); +// ~enable_shared_from_this(); +// public: +// shared_ptr<T> shared_from_this(); +// shared_ptr<T const> shared_from_this() const; +// }; + +#include <memory> +#include <cassert> + +struct T + : public std::enable_shared_from_this<T> +{ +}; + +struct Y : T {}; + +struct Z : Y {}; + +int main() +{ + { // https://llvm.org/bugs/show_bug.cgi?id=18843 + std::shared_ptr<T const> t1(new T); + std::shared_ptr<T const> t2(std::make_shared<T>()); + } + { + std::shared_ptr<Y> p(new Z); + std::shared_ptr<T> q = p->shared_from_this(); + assert(p == q); + assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership + } + { + std::shared_ptr<Y> p = std::make_shared<Z>(); + std::shared_ptr<T> q = p->shared_from_this(); + assert(p == q); + assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp new file mode 100644 index 0000000000000..990cb58722b1c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T> +// struct hash<shared_ptr<T>> +// { +// typedef shared_ptr<T> argument_type; +// typedef size_t result_type; +// size_t operator()(const shared_ptr<T>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::shared_ptr<int> p(ptr); + std::hash<std::shared_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp new file mode 100644 index 0000000000000..5cd4ab1f83d0e --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template <class T, class D> +// struct hash<unique_ptr<T, D>> +// { +// typedef unique_ptr<T, D> argument_type; +// typedef size_t result_type; +// size_t operator()(const unique_ptr<T, D>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::unique_ptr<int> p(ptr); + std::hash<std::unique_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp new file mode 100644 index 0000000000000..2d586e9c7fdd1 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// bool +// atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v, +// shared_ptr<T> w); + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v(new int(3)); + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_strong(&p, &v, w); + assert(b == false); + assert(*p == 4); + assert(*v == 4); + assert(*w == 2); + } + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v = p; + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_strong(&p, &v, w); + assert(b == true); + assert(*p == 2); + assert(*v == 4); + assert(*w == 2); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp new file mode 100644 index 0000000000000..34da04cc18108 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// bool +// atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, +// shared_ptr<T> w, memory_order success, +// memory_order failure); + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v(new int(3)); + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w, + std::memory_order_seq_cst, + std::memory_order_seq_cst); + assert(b == false); + assert(*p == 4); + assert(*v == 4); + assert(*w == 2); + } + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v = p; + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w, + std::memory_order_seq_cst, + std::memory_order_seq_cst); + assert(b == true); + assert(*p == 2); + assert(*v == 4); + assert(*w == 2); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp new file mode 100644 index 0000000000000..50b96e551fd3b --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// bool +// atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, +// shared_ptr<T> w); + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v(new int(3)); + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_weak(&p, &v, w); + assert(b == false); + assert(*p == 4); + assert(*v == 4); + assert(*w == 2); + } + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v = p; + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_weak(&p, &v, w); + assert(b == true); + assert(*p == 2); + assert(*v == 4); + assert(*w == 2); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp new file mode 100644 index 0000000000000..d304319d251de --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// bool +// atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, +// shared_ptr<T> w, memory_order success, +// memory_order failure); + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v(new int(3)); + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w, + std::memory_order_seq_cst, + std::memory_order_seq_cst); + assert(b == false); + assert(*p == 4); + assert(*v == 4); + assert(*w == 2); + } + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> v = p; + std::shared_ptr<int> w(new int(2)); + bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w, + std::memory_order_seq_cst, + std::memory_order_seq_cst); + assert(b == true); + assert(*p == 2); + assert(*v == 4); + assert(*w == 2); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp new file mode 100644 index 0000000000000..3b44c8ba9b330 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// shared_ptr<T> +// atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> r(new int(3)); + r = std::atomic_exchange(&p, r); + assert(*p == 3); + assert(*r == 4); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp new file mode 100644 index 0000000000000..598a1b8da175c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// shared_ptr<T> +// atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(4)); + std::shared_ptr<int> r(new int(3)); + r = std::atomic_exchange_explicit(&p, r, std::memory_order_seq_cst); + assert(*p == 3); + assert(*r == 4); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_is_lock_free.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_is_lock_free.pass.cpp new file mode 100644 index 0000000000000..e3ac84a4fa507 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_is_lock_free.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <memory> + +// shared_ptr + +// template<class T> +// bool +// atomic_is_lock_free(const shared_ptr<T>* p); + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + const std::shared_ptr<int> p(new int(3)); + assert(std::atomic_is_lock_free(&p) == false); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp new file mode 100644 index 0000000000000..d4a39c878ac7a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// shared_ptr<T> +// atomic_load(const shared_ptr<T>* p) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p(new int(3)); + std::shared_ptr<int> q = std::atomic_load(&p); + assert(*q == *p); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp new file mode 100644 index 0000000000000..af11dc8bc2c9c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// shared_ptr<T> +// atomic_load_explicit(const shared_ptr<T>* p, memory_order mo) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + const std::shared_ptr<int> p(new int(3)); + std::shared_ptr<int> q = std::atomic_load_explicit(&p, std::memory_order_relaxed); + assert(*q == *p); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp new file mode 100644 index 0000000000000..7a85a9934ef0a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// void +// atomic_store(shared_ptr<T>* p, shared_ptr<T> r) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p; + std::shared_ptr<int> r(new int(3)); + std::atomic_store(&p, r); + assert(*p == *r); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp new file mode 100644 index 0000000000000..c81266c55fa47 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-no-threads +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <memory> + +// shared_ptr + +// template <class T> +// void +// atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo) + +#include <memory> +#include <cassert> + +int main() +{ +#if __has_feature(cxx_atomic) + { + std::shared_ptr<int> p; + std::shared_ptr<int> r(new int(3)); + std::atomic_store_explicit(&p, r, std::memory_order_seq_cst); + assert(*p == *r); + } +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h new file mode 100644 index 0000000000000..0263061b3a84a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// Example move-only deleter + +#ifndef DELETER_H +#define DELETER_H + +#include <type_traits> +#include <cassert> + +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define DELETE_FUNCTION = delete +#else +#define DELETE_FUNCTION { assert(false); } +#endif + +struct test_deleter_base +{ + static int count; + static int dealloc_count; +}; + +int test_deleter_base::count = 0; +int test_deleter_base::dealloc_count = 0; + +template <class T> +class test_deleter + : public test_deleter_base +{ + int state_; + +public: + + test_deleter() : state_(0) {++count;} + explicit test_deleter(int s) : state_(s) {++count;} + test_deleter(const test_deleter& d) + : state_(d.state_) {++count;} + ~test_deleter() {assert(state_ >= 0); --count; state_ = -1;} + + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;} + + test_deleter* operator&() const DELETE_FUNCTION; +}; + +template <class T> +void +swap(test_deleter<T>& x, test_deleter<T>& y) +{ + test_deleter<T> t(std::move(x)); + x = std::move(y); + y = std::move(t); +} + +#endif // DELETER_H diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp new file mode 100644 index 0000000000000..8175312334f66 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> class shared_ptr +// { +// public: +// typedef T element_type; +// ... +// }; + +#include <memory> + +struct A; // purposefully incomplete + +int main() +{ + static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), ""); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp new file mode 100644 index 0000000000000..a6c62496fd62f --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class D, class T> D* get_deleter(const shared_ptr<T>& p); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } + test_deleter<A>::dealloc_count = 0; + { + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } + test_deleter<A>::dealloc_count = 0; + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p); + assert(d == 0); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..21cdf4a13e476 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::auto_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::auto_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp new file mode 100644 index 0000000000000..5d27a8865f08c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// shared_ptr& operator=(const shared_ptr& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..abd3d378eb716 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + const std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = pA; + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp new file mode 100644 index 0000000000000..93956bcae6634 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp new file mode 100644 index 0000000000000..4194890dda2d8 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// shared_ptr& operator=(shared_ptr&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB(new A); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<A> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +#endif // _LIBCXX_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..30e0fce21e04c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::unique_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB(new B); + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); +// assert(pB.use_count() == 1); // no longer true due to LWG 2415 + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA(new A); + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::unique_ptr<A> pA; + A* ptrA = pA.get(); + { + std::shared_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 0); + assert(A::count == 0); +// assert(pB.use_count() == 1); // no longer true due to LWG 2415 + assert(pA.get() == 0); + assert(pB.get() == ptrA); + } + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp new file mode 100644 index 0000000000000..7d771d03c71f5 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<const A> pA(new A); + std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<const A> pA; + std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp new file mode 100644 index 0000000000000..4f88a5c4351a7 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<B> pB(new A); + std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB); + assert(pA.get() == pB.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pB(new B); + std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB); + assert(pA.get() == 0); + assert(pA.use_count() == 0); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp new file mode 100644 index 0000000000000..98fa13801a8c7 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pA(new A); + std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<A> pA; + std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } + { + const std::shared_ptr<B> pA; + std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA); + assert(pB.get() == pA.get()); + assert(!pB.owner_before(pA) && !pA.owner_before(pB)); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp new file mode 100644 index 0000000000000..f40cbc3d0324a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/cmp_nullptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template <class T> +// bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; +// template <class T> +// bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; +// template <class T> +// bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; +// template <class T> +// bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; +// template <class T> +// bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; +// template <class T> +// bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; +// template <class T> +// bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + const std::shared_ptr<int> p1(new int(1)); + assert(!(p1 == nullptr)); + assert(!(nullptr == p1)); + assert(!(p1 < nullptr)); + assert( (nullptr < p1)); + assert(!(p1 <= nullptr)); + assert( (nullptr <= p1)); + assert( (p1 > nullptr)); + assert(!(nullptr > p1)); + assert( (p1 >= nullptr)); + assert(!(nullptr >= p1)); + + const std::shared_ptr<int> p2; + assert( (p2 == nullptr)); + assert( (nullptr == p2)); + assert(!(p2 < nullptr)); + assert(!(nullptr < p2)); + assert( (p2 <= nullptr)); + assert( (nullptr <= p2)); + assert(!(p2 > nullptr)); + assert(!(nullptr > p2)); + assert( (p2 >= nullptr)); + assert( (nullptr >= p2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp new file mode 100644 index 0000000000000..c4cd1693f4966 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp @@ -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> + +// shared_ptr + +// template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b); +// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + int* ptr1(new int); + int* ptr2(new int); + const std::shared_ptr<int> p1(ptr1); + const std::shared_ptr<int> p2(ptr2); + const std::shared_ptr<int> p3(ptr2, do_nothing); + assert(p1 != p2); + assert(p2 == p3); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp new file mode 100644 index 0000000000000..5a90a9a325fa2 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +void do_nothing(int*) {} + +int main() +{ + int* ptr1(new int); + int* ptr2(new int); + const std::shared_ptr<int> p1(ptr1); + const std::shared_ptr<int> p2(ptr2); + const std::shared_ptr<int> p3(ptr2, do_nothing); + assert((p1 < p2) == (ptr1 < ptr2)); + assert(!(p2 < p3) && !(p3 < p2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp new file mode 100644 index 0000000000000..b2e61faff5ed9 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// 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 Y> explicit shared_ptr(auto_ptr<Y>&& r); + +// UNSUPPORTED: sanitizer-new-delete + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::shared_ptr<B> p(std::move(ptr)); +#else + std::shared_ptr<B> p(ptr); +#endif + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == raw_ptr); + assert(ptr.get() == 0); + } + assert(A::count == 0); + { + std::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + throw_next = true; + try + { +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::shared_ptr<B> p(std::move(ptr)); +#else + std::shared_ptr<B> p(ptr); +#endif + assert(false); + } + catch (...) + { +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(A::count == 1); + assert(B::count == 1); + assert(ptr.get() == raw_ptr); +#else + // Without rvalue references, ptr got copied into + // the shared_ptr destructor and the copy was + // destroyed during unwinding. + assert(A::count == 0); + assert(B::count == 0); +#endif + } + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp new file mode 100644 index 0000000000000..9af5d7ea86191 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr(); + +#include <memory> +#include <cassert> + +int main() +{ + std::shared_ptr<int> p; + assert(p.use_count() == 0); + assert(p.get() == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp new file mode 100644 index 0000000000000..3a9b3a9ca1dee --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr(nullptr_t) + +#include <memory> +#include <cassert> + +int main() +{ + std::shared_ptr<int> p(nullptr); + assert(p.use_count() == 0); + assert(p.get() == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp new file mode 100644 index 0000000000000..7d4dc38d4b9a0 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class D> shared_ptr(nullptr_t, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp new file mode 100644 index 0000000000000..b67f31ee45a85 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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 D, class A> shared_ptr(nullptr_t, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "test_allocator.h" +#include "min_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + test_deleter<A>::dealloc_count = 0; + // Test an allocator with a minimal interface + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(1), bare_allocator<void>()); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count ==1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + test_deleter<A>::dealloc_count = 0; +#if __cplusplus >= 201103L + // Test an allocator that returns class-type pointers + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>()); + assert(A::count == 0); + assert(p.use_count() == 1); + assert(p.get() == 0); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count ==1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp new file mode 100644 index 0000000000000..ab2c73e0c5f1a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class D, class A> shared_ptr(nullptr_t, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + try + { + test_allocator<A>::throw_after = 0; + std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp new file mode 100644 index 0000000000000..97d3f69fb5c4b --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class D> shared_ptr(nullptr_t, D d); + +// UNSUPPORTED: sanitizer-new-delete + +#include <memory> +#include <cassert> +#include <new> +#include <cstdlib> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + throw_next = true; + try + { + std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp new file mode 100644 index 0000000000000..c9cffa1fe25e1 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y> explicit shared_ptr(Y* p); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); + { + A* ptr = new A; + std::shared_ptr<void> p(ptr); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp new file mode 100644 index 0000000000000..43eedee176c2c --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D> shared_ptr(Y* p, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp new file mode 100644 index 0000000000000..1a9c09cdb78ce --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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 Y, class D, class A> shared_ptr(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "test_allocator.h" +#include "min_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + + +int main() +{ + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + test_deleter<A>::dealloc_count = 0; + // Test an allocator with a minimal interface + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), bare_allocator<void>()); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + test_deleter<A>::dealloc_count = 0; +#if __cplusplus >= 201103L + // Test an allocator that returns class-type pointers + { + A* ptr = new A; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), min_allocator<void>()); + assert(A::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp new file mode 100644 index 0000000000000..4220993a5fd11 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "test_allocator.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + A* ptr = new A; + try + { + test_allocator<A>::throw_after = 0; + std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp new file mode 100644 index 0000000000000..ead081645671b --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y, class D> shared_ptr(Y* p, D d); + +// UNSUPPORTED: sanitizer-new-delete + +#include <memory> +#include <cassert> +#include <new> +#include <cstdlib> +#include "../test_deleter.h" + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + A* ptr = new A; + throw_next = true; + try + { + std::shared_ptr<A> p(ptr, test_deleter<A>(3)); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp new file mode 100644 index 0000000000000..041fe9a7853d7 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// template<class Y> explicit shared_ptr(Y* p); + +// UNSUPPORTED: sanitizer-new-delete + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +int main() +{ + { + A* ptr = new A; + throw_next = true; + assert(A::count == 1); + try + { + std::shared_ptr<A> p(ptr); + assert(false); + } + catch (std::bad_alloc&) + { + assert(A::count == 0); + } + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp new file mode 100644 index 0000000000000..e1dcdfc8165fe --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr(const shared_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(A::count == 1); + { + std::shared_ptr<A> pA2(pA); + assert(A::count == 1); + assert(pA.use_count() == 2); + assert(pA2.use_count() == 2); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 1); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA2(pA); + assert(A::count == 0); + assert(pA.use_count() == 0); + assert(pA2.use_count() == 0); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..8b5ffdc1475b0 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), ""); + { + const std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp new file mode 100644 index 0000000000000..f041d9451a6d8 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr(shared_ptr<Y>&& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), ""); + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + B* p = pA.get(); + std::shared_ptr<B> pB(std::move(pA)); + assert(B::count == 1); + assert(A::count == 1); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pB.use_count() == 1); + assert(pA.use_count() == 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(p == pB.get()); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp new file mode 100644 index 0000000000000..fb5262f3b0efc --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + ~B() {--count;} +}; + +int B::count = 0; + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + { + B b; + std::shared_ptr<B> pB(pA, &b); + assert(A::count == 1); + assert(B::count == 1); + assert(pA.use_count() == 2); + assert(pB.use_count() == 2); + assert(pB.get() == &b); + } + assert(pA.use_count() == 1); + assert(A::count == 1); + assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp new file mode 100644 index 0000000000000..b89178e201cfc --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// shared_ptr(shared_ptr&& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(A::count == 1); + { + A* p = pA.get(); + std::shared_ptr<A> pA2(std::move(pA)); + assert(A::count == 1); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 0); + assert(pA2.use_count() == 1); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 2); + assert(pA2.use_count() == 2); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA2.get() == p); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 0); + assert(A::count == 0); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(pA.use_count() == 1); + assert(A::count == 1); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA2(std::move(pA)); + assert(A::count == 0); + assert(pA.use_count() == 0); + assert(pA2.use_count() == 0); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp new file mode 100644 index 0000000000000..5e09d9a7934c1 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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 Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r); + +// UNSUPPORTED: sanitizer-new-delete + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> + +bool throw_next = false; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next) + throw std::bad_alloc(); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + std::free(p); +} + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +void fn ( const std::shared_ptr<int> &) {} +void fn ( const std::shared_ptr<B> &) { assert (false); } + +template <typename T> +void assert_deleter ( T * ) { assert(false); } + +int main() +{ + { + std::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + std::shared_ptr<B> p(std::move(ptr)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == raw_ptr); + assert(ptr.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + throw_next = true; + try + { + std::shared_ptr<B> p(std::move(ptr)); + assert(false); + } + catch (...) + { +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(A::count == 1); + assert(B::count == 1); + assert(ptr.get() == raw_ptr); +#else + assert(A::count == 0); + assert(B::count == 0); + assert(ptr.get() == 0); +#endif + } + } + assert(A::count == 0); + + // LWG 2399 + { + throw_next = false; + fn(std::unique_ptr<int>(new int)); + } + +#if __cplusplus >= 201402L + // LWG 2415 + { + std::unique_ptr<int, void (*)(int*)> p(nullptr, assert_deleter<int>); + std::shared_ptr<int> p2(std::move(p)); // should not call deleter when going out of scope + } +#endif + +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp new file mode 100644 index 0000000000000..a9d8aff145a70 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + try + { + std::shared_ptr<A> sp(wp); + assert(false); + } + catch (std::bad_weak_ptr&) + { + } + assert(A::count == 0); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + std::shared_ptr<A> sp(wp); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + sp0.reset(); + try + { + std::shared_ptr<A> sp(wp); + assert(false); + } + catch (std::bad_weak_ptr&) + { + } + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp new file mode 100644 index 0000000000000..aa77dab51515f --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class T, class A, class... Args> +// shared_ptr<T> allocate_shared(const A& a, Args&&... args); + +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +int new_count = 0; + +struct A +{ + static int count; + + A(int i, char c) : int_(i), char_(c) {++count;} + A(const A& a) + : int_(a.int_), char_(a.char_) + {++count;} + ~A() {--count;} + + int get_int() const {return int_;} + char get_char() const {return char_;} +private: + int int_; + char char_; +}; + +int A::count = 0; + +int main() +{ + { + int i = 67; + char c = 'e'; + std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c); + assert(test_allocator<A>::alloc_count == 1); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } + assert(A::count == 0); + assert(test_allocator<A>::alloc_count == 0); +#if __cplusplus >= 201103L + { + int i = 67; + char c = 'e'; + std::shared_ptr<A> p = std::allocate_shared<A>(min_allocator<void>(), i, c); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } + assert(A::count == 0); + { + int i = 68; + char c = 'f'; + std::shared_ptr<A> p = std::allocate_shared<A>(bare_allocator<void>(), i, c); + assert(A::count == 1); + assert(p->get_int() == 68); + assert(p->get_char() == 'f'); + } + assert(A::count == 0); +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp new file mode 100644 index 0000000000000..8dcd50e494110 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T, class A, class... Args> +// shared_ptr<T> allocate_shared(const A& a, Args&&... args); + +#define _LIBCPP_HAS_NO_VARIADICS +#include <memory> +#include <new> +#include <cstdlib> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +struct Zero +{ + static int count; + Zero() {++count;} + Zero(Zero const &) {++count;} + ~Zero() {--count;} +}; + +int Zero::count = 0; + +struct One +{ + static int count; + int value; + explicit One(int v) : value(v) {++count;} + One(One const & o) : value(o.value) {++count;} + ~One() {--count;} +}; + +int One::count = 0; + + +struct Two +{ + static int count; + int value; + Two(int v, int) : value(v) {++count;} + Two(Two const & o) : value(o.value) {++count;} + ~Two() {--count;} +}; + +int Two::count = 0; + +struct Three +{ + static int count; + int value; + Three(int v, int, int) : value(v) {++count;} + Three(Three const & o) : value(o.value) {++count;} + ~Three() {--count;} +}; + +int Three::count = 0; + +template <class Alloc> +void test() +{ + int const bad = -1; + { + std::shared_ptr<Zero> p = std::allocate_shared<Zero>(Alloc()); + assert(Zero::count == 1); + } + assert(Zero::count == 0); + { + int const i = 42; + std::shared_ptr<One> p = std::allocate_shared<One>(Alloc(), i); + assert(One::count == 1); + assert(p->value == i); + } + assert(One::count == 0); + { + int const i = 42; + std::shared_ptr<Two> p = std::allocate_shared<Two>(Alloc(), i, bad); + assert(Two::count == 1); + assert(p->value == i); + } + assert(Two::count == 0); + { + int const i = 42; + std::shared_ptr<Three> p = std::allocate_shared<Three>(Alloc(), i, bad, bad); + assert(Three::count == 1); + assert(p->value == i); + } + assert(Three::count == 0); +} + +int main() +{ + { + int i = 67; + int const bad = -1; + std::shared_ptr<Two> p = std::allocate_shared<Two>(test_allocator<Two>(54), i, bad); + assert(test_allocator<Two>::alloc_count == 1); + assert(Two::count == 1); + assert(p->value == 67); + } + assert(Two::count == 0); + assert(test_allocator<Two>::alloc_count == 0); + + test<bare_allocator<void> >(); +#if __cplusplus >= 201103L + test<min_allocator<void> >(); +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp new file mode 100644 index 0000000000000..8cb972b0c1a14 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args); + +#include <memory> +#include <cassert> + +#include "count_new.hpp" + +struct A +{ + static int count; + + A(int i, char c) : int_(i), char_(c) {++count;} + A(const A& a) + : int_(a.int_), char_(a.char_) + {++count;} + ~A() {--count;} + + int get_int() const {return int_;} + char get_char() const {return char_;} +private: + int int_; + char char_; +}; + +int A::count = 0; + + +struct Foo +{ + Foo() = default; + virtual ~Foo() = default; +}; + + +int main() +{ + int nc = globalMemCounter.outstanding_new; + { + int i = 67; + char c = 'e'; + std::shared_ptr<A> p = std::make_shared<A>(i, c); + assert(globalMemCounter.checkOutstandingNewEq(nc+1)); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } + + { // https://llvm.org/bugs/show_bug.cgi?id=24137 + std::shared_ptr<Foo> p1 = std::make_shared<Foo>(); + assert(p1.get()); + std::shared_ptr<const Foo> p2 = std::make_shared<const Foo>(); + assert(p2.get()); + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + nc = globalMemCounter.outstanding_new; + { + char c = 'e'; + std::shared_ptr<A> p = std::make_shared<A>(67, c); + assert(globalMemCounter.checkOutstandingNewEq(nc+1)); + assert(A::count == 1); + assert(p->get_int() == 67); + assert(p->get_char() == 'e'); + } +#endif + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp new file mode 100644 index 0000000000000..1045f9347b381 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args); + +#include <memory> +#include <cassert> + +template <typename T> +void test(const T &t0) +{ + { + T t1 = t0; + std::shared_ptr<T> p0 = std::make_shared<T>(t0); + std::shared_ptr<T> p1 = std::make_shared<T>(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } + + { + const T t1 = t0; + std::shared_ptr<const T> p0 = std::make_shared<const T>(t0); + std::shared_ptr<const T> p1 = std::make_shared<const T>(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } + + { + volatile T t1 = t0; + std::shared_ptr<volatile T> p0 = std::make_shared<volatile T>(t0); + std::shared_ptr<volatile T> p1 = std::make_shared<volatile T>(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } + + { + const volatile T t1 = t0; + std::shared_ptr<const volatile T> p0 = std::make_shared<const volatile T>(t0); + std::shared_ptr<const volatile T> p1 = std::make_shared<const volatile T>(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } + +} + +int main() +{ + test<bool>(true); + test<int>(3); + test<double>(5.0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp new file mode 100644 index 0000000000000..b627ac1ccbc93 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class CharT, class Traits, class Y> +// basic_ostream<CharT, Traits>& +// operator<<(basic_ostream<CharT, Traits>& os, shared_ptr<Y> const& p); + +#include <memory> +#include <sstream> +#include <cassert> + +int main() +{ + std::shared_ptr<int> p(new int(3)); + std::ostringstream os; + assert(os.str().empty()); + os << p; + assert(!os.str().empty()); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp new file mode 100644 index 0000000000000..7bffc06993fac --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// void reset(); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + p.reset(); + assert(A::count == 0); + assert(B::count == 0); + assert(p.use_count() == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::shared_ptr<B> p; + p.reset(); + assert(A::count == 0); + assert(B::count == 0); + assert(p.use_count() == 0); + assert(p.get() == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp new file mode 100644 index 0000000000000..85a64d0f1b0ba --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// template<class Y> void reset(Y* p); + +#include <memory> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp new file mode 100644 index 0000000000000..33965dfeb33c0 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y, class D> void reset(Y* p, D d); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 1); + assert(d); + assert(d->state() == 3); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 2); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp new file mode 100644 index 0000000000000..09070e2c059b0 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class Y, class D, class A> void reset(Y* p, D d, A a); + +#include <memory> +#include <cassert> +#include "../test_deleter.h" +#include "test_allocator.h" + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<B> p(new B); + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 0); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 1); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); + { + std::shared_ptr<B> p; + A* ptr = new A; + p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4)); + assert(A::count == 1); + assert(B::count == 1); + assert(p.use_count() == 1); + assert(p.get() == ptr); + test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); + assert(test_deleter<A>::count == 1); + assert(test_deleter<A>::dealloc_count == 1); + assert(d); + assert(d->state() == 3); + assert(test_allocator<A>::count == 1); + assert(test_allocator<A>::alloc_count == 1); + } + assert(A::count == 0); + assert(test_deleter<A>::count == 0); + assert(test_deleter<A>::dealloc_count == 2); + assert(test_allocator<A>::count == 0); + assert(test_allocator<A>::alloc_count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp new file mode 100644 index 0000000000000..6d28a5043ca0d --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// void swap(shared_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2(ptr2); + p1.swap(p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 2); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = new A; + A* ptr2 = 0; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2; + p1.swap(p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = new A; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2(ptr2); + p1.swap(p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = 0; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2; + p1.swap(p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 0); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp new file mode 100644 index 0000000000000..00281687521fd --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// T* operator->() const; + +#include <memory> +#include <utility> +#include <cassert> + +int main() +{ + const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4)); + assert(p->first == 3); + assert(p->second == 4); + p->first = 5; + p->second = 6; + assert(p->first == 5); + assert(p->second == 6); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp new file mode 100644 index 0000000000000..378cd0514ca25 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// T& operator*() const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p(new int(32)); + assert(*p == 32); + *p = 3; + assert(*p == 3); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp new file mode 100644 index 0000000000000..1b79d497005a5 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// shared_ptr + +// explicit operator bool() const; + +#include <memory> +#include <cassert> + +int main() +{ + { + const std::shared_ptr<int> p(new int(32)); + assert(p); + } + { + const std::shared_ptr<int> p; + assert(!p); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp new file mode 100644 index 0000000000000..3acd2f8c6f2d4 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template <class U> bool owner_before(shared_ptr<U> const& b) const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + assert(!p1.owner_before(p2)); + assert(!p2.owner_before(p1)); + assert(p1.owner_before(p3) || p3.owner_before(p1)); + assert(p3.owner_before(p1) == p3.owner_before(p2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp new file mode 100644 index 0000000000000..33447ba7da00f --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp @@ -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> + +// shared_ptr + +// template <class U> bool owner_before(weak_ptr<U> const& b) const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!p1.owner_before(w2)); + assert(!p2.owner_before(w1)); + assert(p1.owner_before(w3) || p3.owner_before(w1)); + assert(p3.owner_before(w1) == p3.owner_before(w2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp new file mode 100644 index 0000000000000..50ff692f9d421 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// bool unique() const; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p(new int(32)); + assert(p.unique()); + { + std::shared_ptr<int> p2 = p; + assert(!p.unique()); + } + assert(p.unique()); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp new file mode 100644 index 0000000000000..b40e4705acfe3 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// shared_ptr + +// template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2(ptr2); + swap(p1, p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 2); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = new A; + A* ptr2 = 0; + std::shared_ptr<A> p1(ptr1); + { + std::shared_ptr<A> p2; + swap(p1, p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 1); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = new A; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2(ptr2); + swap(p1, p2); + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 1); + } + assert(p1.use_count() == 1); + assert(p1.get() == ptr2); + assert(A::count == 1); + } + assert(A::count == 0); + { + A* ptr1 = 0; + A* ptr2 = 0; + std::shared_ptr<A> p1; + { + std::shared_ptr<A> p2; + swap(p1, p2); + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(p2.use_count() == 0); + assert(p2.get() == ptr1); + assert(A::count == 0); + } + assert(p1.use_count() == 0); + assert(p1.get() == ptr2); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp new file mode 100644 index 0000000000000..45748d7db6fbf --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> class weak_ptr +// { +// public: +// typedef T element_type; +// ... +// }; + +#include <memory> + +struct A; // purposefully incomplete + +int main() +{ + static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), ""); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp new file mode 100644 index 0000000000000..d091ae99fc272 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> struct owner_less; +// +// template <class T> +// struct owner_less<shared_ptr<T> > +// : binary_function<shared_ptr<T>, shared_ptr<T>, bool> +// { +// typedef bool result_type; +// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; +// }; +// +// template <class T> +// struct owner_less<weak_ptr<T> > +// : binary_function<weak_ptr<T>, weak_ptr<T>, bool> +// { +// typedef bool result_type; +// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + + { + typedef std::owner_less<std::shared_ptr<int> > CS; + CS cs; + + static_assert((std::is_same<std::shared_ptr<int>, CS::first_argument_type>::value), "" ); + static_assert((std::is_same<std::shared_ptr<int>, CS::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, CS::result_type>::value), "" ); + + assert(!cs(p1, p2)); + assert(!cs(p2, p1)); + assert(cs(p1 ,p3) || cs(p3, p1)); + assert(cs(p3, p1) == cs(p3, p2)); + + assert(!cs(p1, w2)); + assert(!cs(p2, w1)); + assert(cs(p1, w3) || cs(p3, w1)); + assert(cs(p3, w1) == cs(p3, w2)); + } + { + typedef std::owner_less<std::weak_ptr<int> > CS; + CS cs; + + static_assert((std::is_same<std::weak_ptr<int>, CS::first_argument_type>::value), "" ); + static_assert((std::is_same<std::weak_ptr<int>, CS::second_argument_type>::value), "" ); + static_assert((std::is_same<bool, CS::result_type>::value), "" ); + + assert(!cs(w1, w2)); + assert(!cs(w2, w1)); + assert(cs(w1, w3) || cs(w3, w1)); + assert(cs(w3, w1) == cs(w3, w2)); + + assert(!cs(w1, p2)); + assert(!cs(w2, p1)); + assert(cs(w1, p3) || cs(w3, p1)); + assert(cs(w3, p1) == cs(w3, p2)); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..6b32079c71b4b --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// weak_ptr + +// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> pA(new A); + { + std::weak_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp new file mode 100644 index 0000000000000..e5713f375215d --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// weak_ptr& operator=(const weak_ptr& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + { + std::weak_ptr<A> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + + { + const std::shared_ptr<A> ps(new A); + std::weak_ptr<A> pA(ps); + { + std::weak_ptr<A> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + } + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..5a03d926f7d66 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + { + std::weak_ptr<B> pB; + pB = pA; + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + + { + const std::shared_ptr<A> ps(new A); + std::weak_ptr<A> pA(ps); + { + std::weak_ptr<B> pB; + pB = std::move(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + } + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp new file mode 100644 index 0000000000000..28358db6a446f --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> class weak_ptr + +// weak_ptr(); + +#include <memory> +#include <cassert> + +struct A; + +int main() +{ + std::weak_ptr<A> p; + assert(p.use_count() == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..d70adb940eb27 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// weak_ptr + +// template<class Y> weak_ptr(const shared_ptr<Y>& r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +int main() +{ + static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), ""); + { + const std::shared_ptr<A> pA(new A); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp new file mode 100644 index 0000000000000..75bf3df90aa36 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// weak_ptr + +// weak_ptr(const weak_ptr& r); +// weak_ptr(weak_ptr &&r) + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +template <class T> +std::weak_ptr<T> source (std::shared_ptr<T> p) { return std::weak_ptr<T>(p); } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class T> +void sink (std::weak_ptr<T> &&) {} +#endif + +int main() +{ + { + const std::shared_ptr<A> ps(new A); + const std::weak_ptr<A> pA(ps); + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + { + std::weak_ptr<A> pB(pA); + assert(B::count == 1); + assert(A::count == 1); + assert(pB.use_count() == 1); + assert(pA.use_count() == 1); + } + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::shared_ptr<A> ps(new A); + std::weak_ptr<A> pA = source(ps); + assert(pA.use_count() == 1); + assert(A::count == 1); + sink(std::move(pA)); // kill off the weak pointer + } + assert(B::count == 0); + assert(A::count == 0); +#endif +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp new file mode 100644 index 0000000000000..51a8fa5ae81f1 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// template<class Y> weak_ptr(const weak_ptr<Y>& r); +// template<class Y> weak_ptr(weak_ptr<Y> &&r); + +#include <memory> +#include <type_traits> +#include <cassert> + +struct B +{ + static int count; + + B() {++count;} + B(const B&) {++count;} + virtual ~B() {--count;} +}; + +int B::count = 0; + +struct A + : public B +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +struct C +{ + static int count; + + C() {++count;} + C(const C&) {++count;} + virtual ~C() {--count;} +}; + +int C::count = 0; + +template <class T> +std::weak_ptr<T> source (std::shared_ptr<T> p) { return std::weak_ptr<T>(p); } + +int main() +{ + static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), ""); + static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), ""); + { + const std::weak_ptr<A> pA(std::shared_ptr<A>(new A)); + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::weak_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); + + { + std::shared_ptr<A> ps(new A); + std::weak_ptr<A> pA = source(ps); + std::weak_ptr<B> pB(std::move(pA)); + assert(pB.use_count() == 1); + } + assert(B::count == 0); + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp new file mode 100644 index 0000000000000..fa496d4bda592 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// weak_ptr + +// void swap(weak_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::shared_ptr<A> p1(new A); + std::weak_ptr<A> w1(p1); + assert(w1.use_count() == 1); + w1.reset(); + assert(w1.use_count() == 0); + assert(p1.use_count() == 1); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp new file mode 100644 index 0000000000000..4001efb737e42 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp @@ -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> + +// weak_ptr + +// void swap(weak_ptr& r); + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + std::weak_ptr<A> w1(p1); + { + std::shared_ptr<A> p2(ptr2); + std::weak_ptr<A> w2(p2); + w1.swap(w2); + assert(w1.use_count() == 1); + assert(w1.lock().get() == ptr2); + assert(w2.use_count() == 1); + assert(w2.lock().get() == ptr1); + assert(A::count == 2); + } + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp new file mode 100644 index 0000000000000..d61ac51afc620 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// bool expired() const; + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + assert(wp.use_count() == 0); + assert(wp.expired() == (wp.use_count() == 0)); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + assert(wp.use_count() == 1); + assert(wp.expired() == (wp.use_count() == 0)); + sp0.reset(); + assert(wp.use_count() == 0); + assert(wp.expired() == (wp.use_count() == 0)); + } +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp new file mode 100644 index 0000000000000..956884b5c5c44 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// weak_ptr + +// shared_ptr<T> lock() const; + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + std::weak_ptr<A> wp; + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 0); + assert(sp.get() == 0); + assert(A::count == 0); + } + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 2); + assert(sp.get() == sp0.get()); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::shared_ptr<A> sp0(new A); + std::weak_ptr<A> wp(sp0); + sp0.reset(); + std::shared_ptr<A> sp = wp.lock(); + assert(sp.use_count() == 0); + assert(sp.get() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp new file mode 100644 index 0000000000000..ccffc2a66fb57 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp @@ -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> + +// template <class T> class weak_ptr; +// +// not less than comparable + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + + bool b = w1 < w2; +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp new file mode 100644 index 0000000000000..4aa49cfe8a24d --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp @@ -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> + +// weak_ptr + +// template<class U> bool owner_before(const shared_ptr<U>& b); + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!w1.owner_before(p2)); + assert(!w2.owner_before(p1)); + assert(w1.owner_before(p3) || w3.owner_before(p1)); + assert(w3.owner_before(p1) == w3.owner_before(p2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp new file mode 100644 index 0000000000000..9fe2b6e390350 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp @@ -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> + +// weak_ptr + +// template<class U> bool owner_before(const weak_ptr<U>& b); + +#include <memory> +#include <cassert> + +int main() +{ + const std::shared_ptr<int> p1(new int); + const std::shared_ptr<int> p2 = p1; + const std::shared_ptr<int> p3(new int); + const std::weak_ptr<int> w1(p1); + const std::weak_ptr<int> w2(p2); + const std::weak_ptr<int> w3(p3); + assert(!w1.owner_before(w2)); + assert(!w2.owner_before(w1)); + assert(w1.owner_before(w3) || w3.owner_before(w1)); + assert(w3.owner_before(w1) == w3.owner_before(w2)); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp new file mode 100644 index 0000000000000..e13d5aeaf6367 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp @@ -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> + +// weak_ptr + +// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) + +#include <memory> +#include <cassert> + +struct A +{ + static int count; + + A() {++count;} + A(const A&) {++count;} + ~A() {--count;} +}; + +int A::count = 0; + +int main() +{ + { + A* ptr1 = new A; + A* ptr2 = new A; + std::shared_ptr<A> p1(ptr1); + std::weak_ptr<A> w1(p1); + { + std::shared_ptr<A> p2(ptr2); + std::weak_ptr<A> w2(p2); + swap(w1, w2); + assert(w1.use_count() == 1); + assert(w1.lock().get() == ptr2); + assert(w2.use_count() == 1); + assert(w2.lock().get() == ptr1); + assert(A::count == 2); + } + } + assert(A::count == 0); +} diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp new file mode 100644 index 0000000000000..cb895cd2bbf30 --- /dev/null +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp @@ -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> + +// class bad_weak_ptr +// : public std::exception +// { +// public: +// bad_weak_ptr(); +// }; + +#include <memory> +#include <type_traits> +#include <cassert> +#include <cstring> + +int main() +{ + static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), ""); + std::bad_weak_ptr e; + std::bad_weak_ptr e2 = e; + e2 = e; + assert(std::strcmp(e.what(), "bad_weak_ptr") == 0); +} diff --git a/test/std/utilities/memory/version.pass.cpp b/test/std/utilities/memory/version.pass.cpp new file mode 100644 index 0000000000000..790c08a3bd2d9 --- /dev/null +++ b/test/std/utilities/memory/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <memory> + +#include <memory> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/meta/meta.hel/bool_constant.pass.cpp b/test/std/utilities/meta/meta.hel/bool_constant.pass.cpp new file mode 100644 index 0000000000000..71110ea3bfb09 --- /dev/null +++ b/test/std/utilities/meta/meta.hel/bool_constant.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// bool_constant + +#include <type_traits> +#include <cassert> + +int main() +{ +#if __cplusplus > 201402L + typedef std::bool_constant<true> _t; + static_assert(_t::value, ""); + static_assert((std::is_same<_t::value_type, bool>::value), ""); + static_assert((std::is_same<_t::type, _t>::value), ""); + static_assert((_t() == true), ""); + + typedef std::bool_constant<false> _f; + static_assert(!_f::value, ""); + static_assert((std::is_same<_f::value_type, bool>::value), ""); + static_assert((std::is_same<_f::type, _f>::value), ""); + static_assert((_f() == false), ""); +#endif +} diff --git a/test/std/utilities/meta/meta.hel/integral_constant.pass.cpp b/test/std/utilities/meta/meta.hel/integral_constant.pass.cpp new file mode 100644 index 0000000000000..335305a282364 --- /dev/null +++ b/test/std/utilities/meta/meta.hel/integral_constant.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral_constant + +#include <type_traits> +#include <cassert> + +int main() +{ + typedef std::integral_constant<int, 5> _5; + static_assert(_5::value == 5, ""); + static_assert((std::is_same<_5::value_type, int>::value), ""); + static_assert((std::is_same<_5::type, _5>::value), ""); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert((_5() == 5), ""); +#else + assert(_5() == 5); +#endif + +#if _LIBCPP_STD_VER > 11 + static_assert ( _5{}() == 5, "" ); + static_assert ( std::true_type{}(), "" ); +#endif + + static_assert(std::false_type::value == false, ""); + static_assert((std::is_same<std::false_type::value_type, bool>::value), ""); + static_assert((std::is_same<std::false_type::type, std::false_type>::value), ""); + + static_assert(std::true_type::value == true, ""); + static_assert((std::is_same<std::true_type::value_type, bool>::value), ""); + static_assert((std::is_same<std::true_type::type, std::true_type>::value), ""); + + std::false_type f1; + std::false_type f2 = f1; + assert(!f2); + + std::true_type t1; + std::true_type t2 = t1; + assert(t2); +} diff --git a/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp b/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp new file mode 100644 index 0000000000000..0f90ae5c1cab5 --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_base_of.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_base_of + +#include <type_traits> + +template <class T, class U> +void test_is_base_of() +{ + static_assert((std::is_base_of<T, U>::value), ""); + static_assert((std::is_base_of<const T, U>::value), ""); + static_assert((std::is_base_of<T, const U>::value), ""); + static_assert((std::is_base_of<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_not_base_of() +{ + static_assert((!std::is_base_of<T, U>::value), ""); +} + +struct B {}; +struct B1 : B {}; +struct B2 : B {}; +struct D : private B1, private B2 {}; + +int main() +{ + test_is_base_of<B, D>(); + test_is_base_of<B1, D>(); + test_is_base_of<B2, D>(); + test_is_base_of<B, B1>(); + test_is_base_of<B, B2>(); + test_is_base_of<B, B>(); + + test_is_not_base_of<D, B>(); + test_is_not_base_of<B&, D&>(); + test_is_not_base_of<B[3], D[3]>(); + test_is_not_base_of<int, int>(); +} diff --git a/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp b/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp new file mode 100644 index 0000000000000..429fb33037fff --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp @@ -0,0 +1,195 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_convertible + +#include <type_traits> + +template <class T, class U> +void test_is_convertible() +{ + static_assert((std::is_convertible<T, U>::value), ""); + static_assert((std::is_convertible<const T, U>::value), ""); + static_assert((std::is_convertible<T, const U>::value), ""); + static_assert((std::is_convertible<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_not_convertible() +{ + static_assert((!std::is_convertible<T, U>::value), ""); + static_assert((!std::is_convertible<const T, U>::value), ""); + static_assert((!std::is_convertible<T, const U>::value), ""); + static_assert((!std::is_convertible<const T, const U>::value), ""); +} + +typedef void Function(); +typedef char Array[1]; + +class NonCopyable { + NonCopyable(NonCopyable&); +}; + +int main() +{ + // void + test_is_convertible<void,void> (); + test_is_not_convertible<void,Function> (); + test_is_not_convertible<void,Function&> (); + test_is_not_convertible<void,Function*> (); + test_is_not_convertible<void,Array> (); + test_is_not_convertible<void,Array&> (); + test_is_not_convertible<void,char> (); + test_is_not_convertible<void,char&> (); + test_is_not_convertible<void,char*> (); + + // Function + test_is_not_convertible<Function, void> (); + test_is_not_convertible<Function, Function> (); + test_is_convertible<Function, Function&> (); + test_is_convertible<Function, Function*> (); + test_is_not_convertible<Function, Array> (); + test_is_not_convertible<Function, Array&> (); + test_is_not_convertible<Function, char> (); + test_is_not_convertible<Function, char&> (); + test_is_not_convertible<Function, char*> (); + + // Function& + test_is_not_convertible<Function&, void> (); + test_is_not_convertible<Function&, Function> (); + test_is_convertible<Function&, Function&> (); + + test_is_convertible<Function&, Function*> (); + test_is_not_convertible<Function&, Array> (); + test_is_not_convertible<Function&, Array&> (); + test_is_not_convertible<Function&, char> (); + test_is_not_convertible<Function&, char&> (); + test_is_not_convertible<Function&, char*> (); + + // Function* + test_is_not_convertible<Function*, void> (); + test_is_not_convertible<Function*, Function> (); + test_is_not_convertible<Function*, Function&> (); + test_is_convertible<Function*, Function*> (); + + test_is_not_convertible<Function*, Array> (); + test_is_not_convertible<Function*, Array&> (); + test_is_not_convertible<Function*, char> (); + test_is_not_convertible<Function*, char&> (); + test_is_not_convertible<Function*, char*> (); + + // Array + test_is_not_convertible<Array, void> (); + test_is_not_convertible<Array, Function> (); + test_is_not_convertible<Array, Function&> (); + test_is_not_convertible<Array, Function*> (); + test_is_not_convertible<Array, Array> (); + + static_assert((!std::is_convertible<Array, Array&>::value), ""); + static_assert(( std::is_convertible<Array, const Array&>::value), ""); + static_assert((!std::is_convertible<const Array, Array&>::value), ""); + static_assert(( std::is_convertible<const Array, const Array&>::value), ""); + + test_is_not_convertible<Array, char> (); + test_is_not_convertible<Array, char&> (); + + static_assert(( std::is_convertible<Array, char*>::value), ""); + static_assert(( std::is_convertible<Array, const char*>::value), ""); + static_assert((!std::is_convertible<const Array, char*>::value), ""); + static_assert(( std::is_convertible<const Array, const char*>::value), ""); + + // Array& + test_is_not_convertible<Array&, void> (); + test_is_not_convertible<Array&, Function> (); + test_is_not_convertible<Array&, Function&> (); + test_is_not_convertible<Array&, Function*> (); + test_is_not_convertible<Array&, Array> (); + + static_assert(( std::is_convertible<Array&, Array&>::value), ""); + static_assert(( std::is_convertible<Array&, const Array&>::value), ""); + static_assert((!std::is_convertible<const Array&, Array&>::value), ""); + static_assert(( std::is_convertible<const Array&, const Array&>::value), ""); + + test_is_not_convertible<Array&, char> (); + test_is_not_convertible<Array&, char&> (); + + static_assert(( std::is_convertible<Array&, char*>::value), ""); + static_assert(( std::is_convertible<Array&, const char*>::value), ""); + static_assert((!std::is_convertible<const Array&, char*>::value), ""); + static_assert(( std::is_convertible<const Array&, const char*>::value), ""); + + // char + test_is_not_convertible<char, void> (); + test_is_not_convertible<char, Function> (); + test_is_not_convertible<char, Function&> (); + test_is_not_convertible<char, Function*> (); + test_is_not_convertible<char, Array> (); + test_is_not_convertible<char, Array&> (); + + test_is_convertible<char, char> (); + + static_assert((!std::is_convertible<char, char&>::value), ""); + static_assert(( std::is_convertible<char, const char&>::value), ""); + static_assert((!std::is_convertible<const char, char&>::value), ""); + static_assert(( std::is_convertible<const char, const char&>::value), ""); + + test_is_not_convertible<char, char*> (); + + // char& + test_is_not_convertible<char&, void> (); + test_is_not_convertible<char&, Function> (); + test_is_not_convertible<char&, Function&> (); + test_is_not_convertible<char&, Function*> (); + test_is_not_convertible<char&, Array> (); + test_is_not_convertible<char&, Array&> (); + + test_is_convertible<char&, char> (); + + static_assert(( std::is_convertible<char&, char&>::value), ""); + static_assert(( std::is_convertible<char&, const char&>::value), ""); + static_assert((!std::is_convertible<const char&, char&>::value), ""); + static_assert(( std::is_convertible<const char&, const char&>::value), ""); + + test_is_not_convertible<char&, char*> (); + + // char* + test_is_not_convertible<char*, void> (); + test_is_not_convertible<char*, Function> (); + test_is_not_convertible<char*, Function&> (); + test_is_not_convertible<char*, Function*> (); + test_is_not_convertible<char*, Array> (); + test_is_not_convertible<char*, Array&> (); + + test_is_not_convertible<char*, char> (); + test_is_not_convertible<char*, char&> (); + + static_assert(( std::is_convertible<char*, char*>::value), ""); + static_assert(( std::is_convertible<char*, const char*>::value), ""); + static_assert((!std::is_convertible<const char*, char*>::value), ""); + static_assert(( std::is_convertible<const char*, const char*>::value), ""); + + // NonCopyable + static_assert((std::is_convertible<NonCopyable&, NonCopyable&>::value), ""); + static_assert((std::is_convertible<NonCopyable&, const NonCopyable&>::value), ""); + static_assert((std::is_convertible<NonCopyable&, const volatile NonCopyable&>::value), ""); + static_assert((std::is_convertible<NonCopyable&, volatile NonCopyable&>::value), ""); + static_assert((std::is_convertible<const NonCopyable&, const NonCopyable&>::value), ""); + static_assert((std::is_convertible<const NonCopyable&, const volatile NonCopyable&>::value), ""); + static_assert((std::is_convertible<volatile NonCopyable&, const volatile NonCopyable&>::value), ""); + static_assert((std::is_convertible<const volatile NonCopyable&, const volatile NonCopyable&>::value), ""); + static_assert((!std::is_convertible<const NonCopyable&, NonCopyable&>::value), ""); +// This test requires Access control SFINAE which we only have in C++11 or when +// we are using the compiler builtin for is_convertible. +#if __cplusplus >= 201103L || !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + test_is_not_convertible<NonCopyable&, NonCopyable>(); +#endif + +} diff --git a/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp b/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp new file mode 100644 index 0000000000000..bd35ef63d08bf --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_convertible_fallback.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_convertible + +// Test the fallback implementation. + +#define _LIBCPP_USE_IS_CONVERTIBLE_FALLBACK +#include "is_convertible.pass.cpp" + diff --git a/test/std/utilities/meta/meta.rel/is_same.pass.cpp b/test/std/utilities/meta/meta.rel/is_same.pass.cpp new file mode 100644 index 0000000000000..7250d6ca77300 --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_same.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_same + +#include <type_traits> + +template <class T, class U> +void test_is_same() +{ + static_assert((std::is_same<T, U>::value), ""); + static_assert((!std::is_same<const T, U>::value), ""); + static_assert((!std::is_same<T, const U>::value), ""); + static_assert((std::is_same<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_same_ref() +{ + static_assert((std::is_same<T, U>::value), ""); + static_assert((std::is_same<const T, U>::value), ""); + static_assert((std::is_same<T, const U>::value), ""); + static_assert((std::is_same<const T, const U>::value), ""); +} + +template <class T, class U> +void test_is_not_same() +{ + static_assert((!std::is_same<T, U>::value), ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_same<int, int>(); + test_is_same<void, void>(); + test_is_same<Class, Class>(); + test_is_same<int*, int*>(); + test_is_same_ref<int&, int&>(); + + test_is_not_same<int, void>(); + test_is_not_same<void, Class>(); + test_is_not_same<Class, int*>(); + test_is_not_same<int*, int&>(); + test_is_not_same<int&, int>(); +} diff --git a/test/std/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp b/test/std/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/meta/meta.rqmts/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp new file mode 100644 index 0000000000000..28bbedee1749c --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_all_extents.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_all_extents + +#include <type_traits> + +enum Enum {zero, one_}; + +template <class T, class U> +void test_remove_all_extents() +{ + static_assert((std::is_same<typename std::remove_all_extents<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_all_extents_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_remove_all_extents<int, int> (); + test_remove_all_extents<const Enum, const Enum> (); + test_remove_all_extents<int[], int> (); + test_remove_all_extents<const int[], const int> (); + test_remove_all_extents<int[3], int> (); + test_remove_all_extents<const int[3], const int> (); + test_remove_all_extents<int[][3], int> (); + test_remove_all_extents<const int[][3], const int> (); + test_remove_all_extents<int[2][3], int> (); + test_remove_all_extents<const int[2][3], const int> (); + test_remove_all_extents<int[1][2][3], int> (); + test_remove_all_extents<const int[1][2][3], const int> (); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp new file mode 100644 index 0000000000000..c688c26b9a5b7 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.arr/remove_extent.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_extent + +#include <type_traits> + +enum Enum {zero, one_}; + +template <class T, class U> +void test_remove_extent() +{ + static_assert((std::is_same<typename std::remove_extent<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_extent_t<T>, U>::value), ""); +#endif +} + + +int main() +{ + test_remove_extent<int, int> (); + test_remove_extent<const Enum, const Enum> (); + test_remove_extent<int[], int> (); + test_remove_extent<const int[], const int> (); + test_remove_extent<int[3], int> (); + test_remove_extent<const int[3], const int> (); + test_remove_extent<int[][3], int[3]> (); + test_remove_extent<const int[][3], const int[3]> (); + test_remove_extent<int[2][3], int[3]> (); + test_remove_extent<const int[2][3], const int[3]> (); + test_remove_extent<int[1][2][3], int[2][3]> (); + test_remove_extent<const int[1][2][3], const int[2][3]> (); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp new file mode 100644 index 0000000000000..19b1fb4d01b39 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_const + +#include <type_traits> + +template <class T, class U> +void test_add_const_imp() +{ + static_assert((std::is_same<typename std::add_const<T>::type, const U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_const_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_add_const() +{ + test_add_const_imp<T, const T>(); + test_add_const_imp<const T, const T>(); + test_add_const_imp<volatile T, volatile const T>(); + test_add_const_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_const<void>(); + test_add_const<int>(); + test_add_const<int[3]>(); + test_add_const<int&>(); + test_add_const<const int&>(); + test_add_const<int*>(); + test_add_const<const int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp new file mode 100644 index 0000000000000..4905e518e12a9 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_cv.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_cv + +#include <type_traits> + +template <class T, class U> +void test_add_cv_imp() +{ + static_assert((std::is_same<typename std::add_cv<T>::type, const volatile U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_cv_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_add_cv() +{ + test_add_cv_imp<T, const volatile T>(); + test_add_cv_imp<const T, const volatile T>(); + test_add_cv_imp<volatile T, volatile const T>(); + test_add_cv_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_cv<void>(); + test_add_cv<int>(); + test_add_cv<int[3]>(); + test_add_cv<int&>(); + test_add_cv<const int&>(); + test_add_cv<int*>(); + test_add_cv<const int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp new file mode 100644 index 0000000000000..7a12c44a2c6e3 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/add_volatile.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_volatile + +#include <type_traits> + +template <class T, class U> +void test_add_volatile_imp() +{ + static_assert((std::is_same<typename std::add_volatile<T>::type, volatile U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_volatile_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_add_volatile() +{ + test_add_volatile_imp<T, volatile T>(); + test_add_volatile_imp<const T, const volatile T>(); + test_add_volatile_imp<volatile T, volatile T>(); + test_add_volatile_imp<const volatile T, const volatile T>(); +} + +int main() +{ + test_add_volatile<void>(); + test_add_volatile<int>(); + test_add_volatile<int[3]>(); + test_add_volatile<int&>(); + test_add_volatile<const int&>(); + test_add_volatile<int*>(); + test_add_volatile<const int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp new file mode 100644 index 0000000000000..cd2faf786d80a --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_const + +#include <type_traits> + +template <class T, class U> +void test_remove_const_imp() +{ + static_assert((std::is_same<typename std::remove_const<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_const_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_remove_const() +{ + test_remove_const_imp<T, T>(); + test_remove_const_imp<const T, T>(); + test_remove_const_imp<volatile T, volatile T>(); + test_remove_const_imp<const volatile T, volatile T>(); +} + +int main() +{ + test_remove_const<void>(); + test_remove_const<int>(); + test_remove_const<int[3]>(); + test_remove_const<int&>(); + test_remove_const<const int&>(); + test_remove_const<int*>(); + test_remove_const<const int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp new file mode 100644 index 0000000000000..3f6405c8280c3 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_cv.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_cv + +#include <type_traits> + +template <class T, class U> +void test_remove_cv_imp() +{ + static_assert((std::is_same<typename std::remove_cv<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_cv_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_remove_cv() +{ + test_remove_cv_imp<T, T>(); + test_remove_cv_imp<const T, T>(); + test_remove_cv_imp<volatile T, T>(); + test_remove_cv_imp<const volatile T, T>(); +} + +int main() +{ + test_remove_cv<void>(); + test_remove_cv<int>(); + test_remove_cv<int[3]>(); + test_remove_cv<int&>(); + test_remove_cv<const int&>(); + test_remove_cv<int*>(); + test_remove_cv<const int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp new file mode 100644 index 0000000000000..6258a9039b400 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.cv/remove_volatile.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_volatile + +#include <type_traits> + +template <class T, class U> +void test_remove_volatile_imp() +{ + static_assert((std::is_same<typename std::remove_volatile<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_volatile_t<T>, U>::value), ""); +#endif +} + +template <class T> +void test_remove_volatile() +{ + test_remove_volatile_imp<T, T>(); + test_remove_volatile_imp<const T, const T>(); + test_remove_volatile_imp<volatile T, T>(); + test_remove_volatile_imp<const volatile T, const T>(); +} + +int main() +{ + test_remove_volatile<void>(); + test_remove_volatile<int>(); + test_remove_volatile<int[3]>(); + test_remove_volatile<int&>(); + test_remove_volatile<const int&>(); + test_remove_volatile<int*>(); + test_remove_volatile<volatile int*>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp new file mode 100644 index 0000000000000..c87e99c46e808 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// aligned_storage + +#include <type_traits> + +int main() +{ + { + typedef std::aligned_storage<10, 1 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 1>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 1, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_storage<10, 2 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 2>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_storage<10, 4 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 4>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 12, ""); + } + { + typedef std::aligned_storage<10, 8 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 8>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<10, 16 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 16>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<10, 32 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10, 32>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 32, ""); + } + { + typedef std::aligned_storage<20, 32 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<20, 32>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 32, ""); + } + { + typedef std::aligned_storage<40, 32 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<40, 32>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 32, ""); + static_assert(sizeof(T1) == 64, ""); + } + { + typedef std::aligned_storage<12, 16 >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<12, 16>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 16, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<1>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<1>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 1, ""); + static_assert(sizeof(T1) == 1, ""); + } + { + typedef std::aligned_storage<2>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<2>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 2, ""); + } + { + typedef std::aligned_storage<3>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<3>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_storage<4>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<4>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_storage<5>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<5>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<7>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<8>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<8>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 8, ""); + } + { + typedef std::aligned_storage<9>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<9>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<15>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<15>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } + // Use alignof(std::max_align_t) below to find the max alignment instead of + // hardcoding it, because it's different on different platforms. + // (For example 8 on arm and 16 on x86.) +#if __cplusplus < 201103L +#define alignof __alignof__ +#endif + { + typedef std::aligned_storage<16>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t), + ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_storage<17>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t), + ""); + static_assert(sizeof(T1) == 16 + alignof(std::max_align_t), ""); + } + { + typedef std::aligned_storage<10>::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp new file mode 100644 index 0000000000000..ae849ca545580 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// aligned_union<size_t Len, class ...Types> + +#include <type_traits> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + { + typedef std::aligned_union<10, char >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, char>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 1, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_union<10, short >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, short>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_union<10, int >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, int>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 12, ""); + } + { + typedef std::aligned_union<10, double >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, double>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 8, ""); + static_assert(sizeof(T1) == 16, ""); + } + { + typedef std::aligned_union<10, short, char >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, short, char>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_union<10, char, short >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<10, char, short>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 2, ""); + static_assert(sizeof(T1) == 10, ""); + } + { + typedef std::aligned_union<2, int, char, short >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<2, int, char, short>, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_union<2, char, int, short >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<2, char, int, short >, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 4, ""); + } + { + typedef std::aligned_union<2, char, short, int >::type T1; +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_same<std::aligned_union_t<2, char, short, int >, T1>::value, "" ); +#endif + static_assert(std::alignment_of<T1>::value == 4, ""); + static_assert(sizeof(T1) == 4, ""); + } +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp new file mode 100644 index 0000000000000..91bf7e7654e03 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// common_type + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::common_type<int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<char>::type, char>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::common_type_t<int>, int>::value), ""); + static_assert((std::is_same<std::common_type_t<char>, char>::value), ""); +#endif + + static_assert((std::is_same<std::common_type< int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type< volatile int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const volatile int>::type, int>::value), ""); + + static_assert((std::is_same<std::common_type<int, int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<int, const int>::type, int>::value), ""); + + static_assert((std::is_same<std::common_type<long, const int>::type, long>::value), ""); + static_assert((std::is_same<std::common_type<const long, int>::type, long>::value), ""); + static_assert((std::is_same<std::common_type<long, volatile int>::type, long>::value), ""); + static_assert((std::is_same<std::common_type<volatile long, int>::type, long>::value), ""); + static_assert((std::is_same<std::common_type<const long, const int>::type, long>::value), ""); + + static_assert((std::is_same<std::common_type<double, char>::type, double>::value), ""); + static_assert((std::is_same<std::common_type<short, char>::type, int>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::common_type_t<double, char>, double>::value), ""); + static_assert((std::is_same<std::common_type_t<short, char>, int>::value), ""); +#endif + + static_assert((std::is_same<std::common_type<double, char, long long>::type, double>::value), ""); + static_assert((std::is_same<std::common_type<unsigned, char, long long>::type, long long>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::common_type_t<double, char, long long>, double>::value), ""); + static_assert((std::is_same<std::common_type_t<unsigned, char, long long>, long long>::value), ""); +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp new file mode 100644 index 0000000000000..ac11e3a4ce86e --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/conditional.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// conditional + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::conditional<true, char, int>::type, char>::value), ""); + static_assert((std::is_same<std::conditional<false, char, int>::type, int>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::conditional_t<true, char, int>, char>::value), ""); + static_assert((std::is_same<std::conditional_t<false, char, int>, int>::value), ""); +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp new file mode 100644 index 0000000000000..bd8ae0e297bcb --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// decay + +#include <type_traits> + +template <class T, class U> +void test_decay() +{ + static_assert((std::is_same<typename std::decay<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::decay_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_decay<void, void>(); + test_decay<int, int>(); + test_decay<const volatile int, int>(); + test_decay<int*, int*>(); + test_decay<int[3], int*>(); + test_decay<const int[3], const int*>(); + test_decay<void(), void (*)()>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp new file mode 100644 index 0000000000000..1ab07670fc268 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enable_if + +#include <type_traits> + +int main() +{ + typedef std::enable_if<false>::type A; +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp new file mode 100644 index 0000000000000..eb72b0f393b3d --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enable_if + +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::enable_if<true>::type, void>::value), ""); + static_assert((std::is_same<std::enable_if<true, int>::type, int>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::enable_if_t<true>, void>::value), ""); + static_assert((std::is_same<std::enable_if_t<true, int>, int>::value), ""); +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if2.fail.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if2.fail.cpp new file mode 100644 index 0000000000000..8ce894578c4fd --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/enable_if2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enable_if + +#include <type_traits> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::enable_if_t<false> A; +#else + static_assert ( false, "" ); +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp new file mode 100644 index 0000000000000..5a925bb34b260 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -0,0 +1,252 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// result_of<Fn(ArgTypes...)> + +#include <type_traits> +#include <memory> +#include "test_macros.h" + +struct S +{ + typedef short (*FreeFunc)(long); + operator FreeFunc() const; + double operator()(char, int&); + double const& operator()(char, int&) const; + double volatile& operator()(char, int&) volatile; + double const volatile& operator()(char, int&) const volatile; +}; + +template <class Tp> +struct Voider { + typedef void type; +}; + +template <class T, class = void> +struct HasType : std::false_type {}; + +template <class T> +struct HasType<T, typename Voider<typename T::type>::type> : std::true_type {}; + +template <class T, class U> +void test_result_of() +{ + static_assert((std::is_same<typename std::result_of<T>::type, U>::value), ""); +} + +template <class T> +void test_no_result() +{ +#if TEST_STD_VER >= 11 + static_assert((!HasType<std::result_of<T> >::value), ""); +#endif +} + +int main() +{ + { // functor object + test_result_of<S(int), short> (); + test_result_of<S&(unsigned char, int&), double> (); + test_result_of<S const&(unsigned char, int&), double const &> (); + test_result_of<S volatile&(unsigned char, int&), double volatile&> (); + test_result_of<S const volatile&(unsigned char, int&), double const volatile&> (); + } + { // pointer to function + typedef bool (&RF0)(); + typedef bool* (&RF1)(int); + typedef bool& (&RF2)(int, int); + typedef bool const& (&RF3)(int, int, int); + typedef bool (*PF0)(); + typedef bool* (*PF1)(int); + typedef bool& (*PF2)(int, int); + typedef bool const& (*PF3)(int, int, int); + typedef bool (*&PRF0)(); + typedef bool* (*&PRF1)(int); + typedef bool& (*&PRF2)(int, int); + typedef bool const& (*&PRF3)(int, int, int); + test_result_of<RF0(), bool>(); + test_result_of<RF1(int), bool*>(); + test_result_of<RF2(int, long), bool&>(); + test_result_of<RF3(int, long, int), bool const&>(); + test_result_of<PF0(), bool>(); + test_result_of<PF1(int), bool*>(); + test_result_of<PF2(int, long), bool&>(); + test_result_of<PF3(int, long, int), bool const&>(); + test_result_of<PRF0(), bool>(); + test_result_of<PRF1(int), bool*>(); + test_result_of<PRF2(int, long), bool&>(); + test_result_of<PRF3(int, long, int), bool const&>(); + } + { // pointer to member function + + typedef int (S::*PMS0)(); + typedef int* (S::*PMS1)(long); + typedef int& (S::*PMS2)(long, int); + test_result_of<PMS0( S), int> (); + test_result_of<PMS0( S&), int> (); + test_result_of<PMS0( S*), int> (); + test_result_of<PMS0( S*&), int> (); + test_result_of<PMS0(std::unique_ptr<S>), int> (); + test_no_result<PMS0(const S&)>(); + test_no_result<PMS0(volatile S&)>(); + test_no_result<PMS0(const volatile S&)>(); + + test_result_of<PMS1( S, int), int*> (); + test_result_of<PMS1( S&, int), int*> (); + test_result_of<PMS1( S*, int), int*> (); + test_result_of<PMS1( S*&, int), int*> (); + test_result_of<PMS1(std::unique_ptr<S>, int), int*> (); + test_no_result<PMS1(const S&, int)>(); + test_no_result<PMS1(volatile S&, int)>(); + test_no_result<PMS1(const volatile S&, int)>(); + + test_result_of<PMS2( S, int, int), int&> (); + test_result_of<PMS2( S&, int, int), int&> (); + test_result_of<PMS2( S*, int, int), int&> (); + test_result_of<PMS2( S*&, int, int), int&> (); + test_result_of<PMS2(std::unique_ptr<S>, int, int), int&> (); + test_no_result<PMS2(const S&, int, int)>(); + test_no_result<PMS2(volatile S&, int, int)>(); + test_no_result<PMS2(const volatile S&, int, int)>(); + + typedef int (S::*PMS0C)() const; + typedef int* (S::*PMS1C)(long) const; + typedef int& (S::*PMS2C)(long, int) const; + test_result_of<PMS0C( S), int> (); + test_result_of<PMS0C( S&), int> (); + test_result_of<PMS0C(const S&), int> (); + test_result_of<PMS0C( S*), int> (); + test_result_of<PMS0C(const S*), int> (); + test_result_of<PMS0C( S*&), int> (); + test_result_of<PMS0C(const S*&), int> (); + test_result_of<PMS0C(std::unique_ptr<S>), int> (); + test_no_result<PMS0C(volatile S&)>(); + test_no_result<PMS0C(const volatile S&)>(); + + test_result_of<PMS1C( S, int), int*> (); + test_result_of<PMS1C( S&, int), int*> (); + test_result_of<PMS1C(const S&, int), int*> (); + test_result_of<PMS1C( S*, int), int*> (); + test_result_of<PMS1C(const S*, int), int*> (); + test_result_of<PMS1C( S*&, int), int*> (); + test_result_of<PMS1C(const S*&, int), int*> (); + test_result_of<PMS1C(std::unique_ptr<S>, int), int*> (); + test_no_result<PMS1C(volatile S&, int)>(); + test_no_result<PMS1C(const volatile S&, int)>(); + + test_result_of<PMS2C( S, int, int), int&> (); + test_result_of<PMS2C( S&, int, int), int&> (); + test_result_of<PMS2C(const S&, int, int), int&> (); + test_result_of<PMS2C( S*, int, int), int&> (); + test_result_of<PMS2C(const S*, int, int), int&> (); + test_result_of<PMS2C( S*&, int, int), int&> (); + test_result_of<PMS2C(const S*&, int, int), int&> (); + test_result_of<PMS2C(std::unique_ptr<S>, int, int), int&> (); + test_no_result<PMS2C(volatile S&, int, int)>(); + test_no_result<PMS2C(const volatile S&, int, int)>(); + + typedef int (S::*PMS0V)() volatile; + typedef int* (S::*PMS1V)(long) volatile; + typedef int& (S::*PMS2V)(long, int) volatile; + test_result_of<PMS0V( S), int> (); + test_result_of<PMS0V( S&), int> (); + test_result_of<PMS0V(volatile S&), int> (); + test_result_of<PMS0V( S*), int> (); + test_result_of<PMS0V(volatile S*), int> (); + test_result_of<PMS0V( S*&), int> (); + test_result_of<PMS0V(volatile S*&), int> (); + test_result_of<PMS0V(std::unique_ptr<S>), int> (); + test_no_result<PMS0V(const S&)>(); + test_no_result<PMS0V(const volatile S&)>(); + + test_result_of<PMS1V( S, int), int*> (); + test_result_of<PMS1V( S&, int), int*> (); + test_result_of<PMS1V(volatile S&, int), int*> (); + test_result_of<PMS1V( S*, int), int*> (); + test_result_of<PMS1V(volatile S*, int), int*> (); + test_result_of<PMS1V( S*&, int), int*> (); + test_result_of<PMS1V(volatile S*&, int), int*> (); + test_result_of<PMS1V(std::unique_ptr<S>, int), int*> (); + test_no_result<PMS1V(const S&, int)>(); + test_no_result<PMS1V(const volatile S&, int)>(); + + test_result_of<PMS2V( S, int, int), int&> (); + test_result_of<PMS2V( S&, int, int), int&> (); + test_result_of<PMS2V(volatile S&, int, int), int&> (); + test_result_of<PMS2V( S*, int, int), int&> (); + test_result_of<PMS2V(volatile S*, int, int), int&> (); + test_result_of<PMS2V( S*&, int, int), int&> (); + test_result_of<PMS2V(volatile S*&, int, int), int&> (); + test_result_of<PMS2V(std::unique_ptr<S>, int, int), int&> (); + test_no_result<PMS2V(const S&, int, int)>(); + test_no_result<PMS2V(const volatile S&, int, int)>(); + + typedef int (S::*PMS0CV)() const volatile; + typedef int* (S::*PMS1CV)(long) const volatile; + typedef int& (S::*PMS2CV)(long, int) const volatile; + test_result_of<PMS0CV( S), int> (); + test_result_of<PMS0CV( S&), int> (); + test_result_of<PMS0CV(const S&), int> (); + test_result_of<PMS0CV(volatile S&), int> (); + test_result_of<PMS0CV(const volatile S&), int> (); + test_result_of<PMS0CV( S*), int> (); + test_result_of<PMS0CV(const S*), int> (); + test_result_of<PMS0CV(volatile S*), int> (); + test_result_of<PMS0CV(const volatile S*), int> (); + test_result_of<PMS0CV( S*&), int> (); + test_result_of<PMS0CV(const S*&), int> (); + test_result_of<PMS0CV(volatile S*&), int> (); + test_result_of<PMS0CV(const volatile S*&), int> (); + test_result_of<PMS0CV(std::unique_ptr<S>), int> (); + + test_result_of<PMS1CV( S, int), int*> (); + test_result_of<PMS1CV( S&, int), int*> (); + test_result_of<PMS1CV(const S&, int), int*> (); + test_result_of<PMS1CV(volatile S&, int), int*> (); + test_result_of<PMS1CV(const volatile S&, int), int*> (); + test_result_of<PMS1CV( S*, int), int*> (); + test_result_of<PMS1CV(const S*, int), int*> (); + test_result_of<PMS1CV(volatile S*, int), int*> (); + test_result_of<PMS1CV(const volatile S*, int), int*> (); + test_result_of<PMS1CV( S*&, int), int*> (); + test_result_of<PMS1CV(const S*&, int), int*> (); + test_result_of<PMS1CV(volatile S*&, int), int*> (); + test_result_of<PMS1CV(const volatile S*&, int), int*> (); + test_result_of<PMS1CV(std::unique_ptr<S>, int), int*> (); + + test_result_of<PMS2CV( S, int, int), int&> (); + test_result_of<PMS2CV( S&, int, int), int&> (); + test_result_of<PMS2CV(const S&, int, int), int&> (); + test_result_of<PMS2CV(volatile S&, int, int), int&> (); + test_result_of<PMS2CV(const volatile S&, int, int), int&> (); + test_result_of<PMS2CV( S*, int, int), int&> (); + test_result_of<PMS2CV(const S*, int, int), int&> (); + test_result_of<PMS2CV(volatile S*, int, int), int&> (); + test_result_of<PMS2CV(const volatile S*, int, int), int&> (); + test_result_of<PMS2CV( S*&, int, int), int&> (); + test_result_of<PMS2CV(const S*&, int, int), int&> (); + test_result_of<PMS2CV(volatile S*&, int, int), int&> (); + test_result_of<PMS2CV(const volatile S*&, int, int), int&> (); + test_result_of<PMS2CV(std::unique_ptr<S>, int, int), int&> (); + } + { // pointer to member data + typedef char S::*PMD; + test_result_of<PMD(S&), char &>(); + test_result_of<PMD(S*), char &>(); + test_result_of<PMD(S* const), char &>(); + test_result_of<PMD(const S&), const char&> (); + test_result_of<PMD(const S*), const char&> (); + test_result_of<PMD(volatile S&), volatile char&> (); + test_result_of<PMD(volatile S*), volatile char&> (); + test_result_of<PMD(const volatile S&), const volatile char&> (); + test_result_of<PMD(const volatile S*), const volatile char&> (); + } +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp new file mode 100644 index 0000000000000..6996cddc08b90 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +// <functional> +// +// result_of<Fn(ArgTypes...)> + +#include <type_traits> +#include "test_macros.h" + +struct wat +{ + wat& operator*() { return *this; } + void foo(); +}; + +struct F {}; + +template <class T, class U> +void test_result_of_imp() +{ + static_assert((std::is_same<typename std::result_of<T>::type, U>::value), ""); +#if TEST_STD_VER > 11 + static_assert((std::is_same<std::result_of_t<T>, U>::value), ""); +#endif +} + +int main() +{ + { + typedef char F::*PMD; + test_result_of_imp<PMD(F &), char &>(); + test_result_of_imp<PMD(F const &), char const &>(); + test_result_of_imp<PMD(F volatile &), char volatile &>(); + test_result_of_imp<PMD(F const volatile &), char const volatile &>(); + + test_result_of_imp<PMD(F &&), char &&>(); + test_result_of_imp<PMD(F const &&), char const &&>(); + test_result_of_imp<PMD(F volatile &&), char volatile &&>(); + test_result_of_imp<PMD(F const volatile &&), char const volatile &&>(); + + test_result_of_imp<PMD(F ), char &&>(); + test_result_of_imp<PMD(F const ), char &&>(); + test_result_of_imp<PMD(F volatile ), char &&>(); + test_result_of_imp<PMD(F const volatile ), char &&>(); + } + { + test_result_of_imp<int (F::* (F &)) () &, int> (); + test_result_of_imp<int (F::* (F &)) () const &, int> (); + test_result_of_imp<int (F::* (F &)) () volatile &, int> (); + test_result_of_imp<int (F::* (F &)) () const volatile &, int> (); + test_result_of_imp<int (F::* (F const &)) () const &, int> (); + test_result_of_imp<int (F::* (F const &)) () const volatile &, int> (); + test_result_of_imp<int (F::* (F volatile &)) () volatile &, int> (); + test_result_of_imp<int (F::* (F volatile &)) () const volatile &, int> (); + test_result_of_imp<int (F::* (F const volatile &)) () const volatile &, int> (); + + test_result_of_imp<int (F::* (F &&)) () &&, int> (); + test_result_of_imp<int (F::* (F &&)) () const &&, int> (); + test_result_of_imp<int (F::* (F &&)) () volatile &&, int> (); + test_result_of_imp<int (F::* (F &&)) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F const &&)) () const &&, int> (); + test_result_of_imp<int (F::* (F const &&)) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F volatile &&)) () volatile &&, int> (); + test_result_of_imp<int (F::* (F volatile &&)) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F const volatile &&)) () const volatile &&, int> (); + + test_result_of_imp<int (F::* (F )) () &&, int> (); + test_result_of_imp<int (F::* (F )) () const &&, int> (); + test_result_of_imp<int (F::* (F )) () volatile &&, int> (); + test_result_of_imp<int (F::* (F )) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F const )) () const &&, int> (); + test_result_of_imp<int (F::* (F const )) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F volatile )) () volatile &&, int> (); + test_result_of_imp<int (F::* (F volatile )) () const volatile &&, int> (); + test_result_of_imp<int (F::* (F const volatile )) () const volatile &&, int> (); + } + + test_result_of_imp<decltype(&wat::foo)(wat), void>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp new file mode 100644 index 0000000000000..728062b70684a --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// underlying_type + +#include <type_traits> +#include <climits> + +enum E { V = INT_MIN }; +enum F { W = UINT_MAX }; + +int main() +{ + static_assert((std::is_same<std::underlying_type<E>::type, int>::value), + "E has the wrong underlying type"); + static_assert((std::is_same<std::underlying_type<F>::type, unsigned>::value), + "F has the wrong underlying type"); + +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::underlying_type_t<E>, int>::value), ""); + static_assert((std::is_same<std::underlying_type_t<F>, unsigned>::value), ""); +#endif + +#if __has_feature(cxx_strong_enums) + enum G : char { }; + + static_assert((std::is_same<std::underlying_type<G>::type, char>::value), + "G has the wrong underlying type"); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::underlying_type_t<G>, char>::value), ""); +#endif +#endif // __has_feature(cxx_strong_enums) +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp new file mode 100644 index 0000000000000..76d0f12d03fb5 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.ptr/add_pointer.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_pointer + +#include <type_traits> + +template <class T, class U> +void test_add_pointer() +{ + static_assert((std::is_same<typename std::add_pointer<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_pointer_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_add_pointer<void, void*>(); + test_add_pointer<int, int*>(); + test_add_pointer<int[3], int(*)[3]>(); + test_add_pointer<int&, int*>(); + test_add_pointer<const int&, const int*>(); + test_add_pointer<int*, int**>(); + test_add_pointer<const int*, const int**>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp new file mode 100644 index 0000000000000..9cecd39049fc4 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.ptr/remove_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_pointer + +#include <type_traits> + +template <class T, class U> +void test_remove_pointer() +{ + static_assert((std::is_same<typename std::remove_pointer<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_pointer_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_remove_pointer<void, void>(); + test_remove_pointer<int, int>(); + test_remove_pointer<int[3], int[3]>(); + test_remove_pointer<int*, int>(); + test_remove_pointer<const int*, const int>(); + test_remove_pointer<int**, int*>(); + test_remove_pointer<int** const, int*>(); + test_remove_pointer<int*const * , int* const>(); + test_remove_pointer<const int** , const int*>(); + + test_remove_pointer<int&, int&>(); + test_remove_pointer<const int&, const int&>(); + test_remove_pointer<int(&)[3], int(&)[3]>(); + test_remove_pointer<int(*)[3], int[3]>(); + test_remove_pointer<int*&, int*&>(); + test_remove_pointer<const int*&, const int*&>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp new file mode 100644 index 0000000000000..8150ce04e37fd --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.ref/add_lvalue_ref.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_lvalue_reference + +#include <type_traits> + +template <class T, class U> +void test_add_lvalue_reference() +{ + static_assert((std::is_same<typename std::add_lvalue_reference<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_lvalue_reference_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_add_lvalue_reference<void, void>(); + test_add_lvalue_reference<int, int&>(); + test_add_lvalue_reference<int[3], int(&)[3]>(); + test_add_lvalue_reference<int&, int&>(); + test_add_lvalue_reference<const int&, const int&>(); + test_add_lvalue_reference<int*, int*&>(); + test_add_lvalue_reference<const int*, const int*&>(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp new file mode 100644 index 0000000000000..e8f08fdc398ad --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// add_rvalue_reference + +#include <type_traits> + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class T, class U> +void test_add_rvalue_reference() +{ + static_assert((std::is_same<typename std::add_rvalue_reference<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::add_rvalue_reference_t<T>, U>::value), ""); +#endif +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_add_rvalue_reference<void, void>(); + test_add_rvalue_reference<int, int&&>(); + test_add_rvalue_reference<int[3], int(&&)[3]>(); + test_add_rvalue_reference<int&, int&>(); + test_add_rvalue_reference<const int&, const int&>(); + test_add_rvalue_reference<int*, int*&&>(); + test_add_rvalue_reference<const int*, const int*&&>(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp new file mode 100644 index 0000000000000..f9ebc37a5dd28 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.ref/remove_ref.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// remove_reference + +#include <type_traits> + +template <class T, class U> +void test_remove_reference() +{ + static_assert((std::is_same<typename std::remove_reference<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::remove_reference_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_remove_reference<void, void>(); + test_remove_reference<int, int>(); + test_remove_reference<int[3], int[3]>(); + test_remove_reference<int*, int*>(); + test_remove_reference<const int*, const int*>(); + + test_remove_reference<int&, int>(); + test_remove_reference<const int&, const int>(); + test_remove_reference<int(&)[3], int[3]>(); + test_remove_reference<int*&, int*>(); + test_remove_reference<const int*&, const int*>(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_remove_reference<int&&, int>(); + test_remove_reference<const int&&, const int>(); + test_remove_reference<int(&&)[3], int[3]>(); + test_remove_reference<int*&&, int*>(); + test_remove_reference<const int*&&, const int*>(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp new file mode 100644 index 0000000000000..eb8e31c76e102 --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// make_signed + +#include <type_traits> + +enum Enum {zero, one_}; + +enum BigEnum +{ + bigzero, + big = 0xFFFFFFFFFFFFFFFFULL +}; + +#if !defined(_LIBCPP_HAS_NO_INT128) && !defined(_LIBCPP_HAS_NO_STRONG_ENUMS) +enum HugeEnum : __uint128_t +{ + hugezero +}; +#endif + +template <class T, class U> +void test_make_signed() +{ + static_assert((std::is_same<typename std::make_signed<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::make_signed_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_make_signed< signed char, signed char >(); + test_make_signed< unsigned char, signed char >(); + test_make_signed< char, signed char >(); + test_make_signed< short, signed short >(); + test_make_signed< unsigned short, signed short >(); + test_make_signed< int, signed int >(); + test_make_signed< unsigned int, signed int >(); + test_make_signed< long, signed long >(); + test_make_signed< unsigned long, long >(); + test_make_signed< long long, signed long long >(); + test_make_signed< unsigned long long, signed long long >(); + test_make_signed< wchar_t, std::conditional<sizeof(wchar_t) == 4, int, short>::type >(); + test_make_signed< const wchar_t, std::conditional<sizeof(wchar_t) == 4, const int, const short>::type >(); + test_make_signed< const Enum, std::conditional<sizeof(Enum) == sizeof(int), const int, const signed char>::type >(); + test_make_signed< BigEnum, std::conditional<sizeof(long) == 4, long long, long>::type >(); +#ifndef _LIBCPP_HAS_NO_INT128 + test_make_signed< __int128_t, __int128_t >(); + test_make_signed< __uint128_t, __int128_t >(); +# ifndef _LIBCPP_HAS_NO_STRONG_ENUMS + test_make_signed< HugeEnum, __int128_t >(); +# endif +#endif +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp new file mode 100644 index 0000000000000..984440193fa6e --- /dev/null +++ b/test/std/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// make_unsigned + +#include <type_traits> + +enum Enum {zero, one_}; + +enum BigEnum +{ + bigzero, + big = 0xFFFFFFFFFFFFFFFFULL +}; + +#if !defined(_LIBCPP_HAS_NO_INT128) && !defined(_LIBCPP_HAS_NO_STRONG_ENUMS) +enum HugeEnum : __int128_t +{ + hugezero +}; +#endif + +template <class T, class U> +void test_make_unsigned() +{ + static_assert((std::is_same<typename std::make_unsigned<T>::type, U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<std::make_unsigned_t<T>, U>::value), ""); +#endif +} + +int main() +{ + test_make_unsigned<signed char, unsigned char> (); + test_make_unsigned<unsigned char, unsigned char> (); + test_make_unsigned<char, unsigned char> (); + test_make_unsigned<short, unsigned short> (); + test_make_unsigned<unsigned short, unsigned short> (); + test_make_unsigned<int, unsigned int> (); + test_make_unsigned<unsigned int, unsigned int> (); + test_make_unsigned<long, unsigned long> (); + test_make_unsigned<unsigned long, unsigned long> (); + test_make_unsigned<long long, unsigned long long> (); + test_make_unsigned<unsigned long long, unsigned long long> (); + test_make_unsigned<wchar_t, std::conditional<sizeof(wchar_t) == 4, unsigned int, unsigned short>::type> (); + test_make_unsigned<const wchar_t, std::conditional<sizeof(wchar_t) == 4, const unsigned int, const unsigned short>::type> (); + test_make_unsigned<const Enum, std::conditional<sizeof(Enum) == sizeof(int), const unsigned int, const unsigned char>::type >(); + test_make_unsigned<BigEnum, + std::conditional<sizeof(long) == 4, unsigned long long, unsigned long>::type> (); +#ifndef _LIBCPP_HAS_NO_INT128 + test_make_unsigned<__int128_t, __uint128_t>(); + test_make_unsigned<__uint128_t, __uint128_t>(); +# ifndef _LIBCPP_HAS_NO_STRONG_ENUMS + test_make_unsigned<HugeEnum, __uint128_t>(); +# endif +#endif +} diff --git a/test/std/utilities/meta/meta.trans/nothing_to_do.pass.cpp b/test/std/utilities/meta/meta.trans/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/meta/meta.trans/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp b/test/std/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/meta/meta.type.synop/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp b/test/std/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp new file mode 100644 index 0000000000000..6ea1cac789efb --- /dev/null +++ b/test/std/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// alignment_of + +#include <type_traits> +#include <cstdint> + +template <class T, unsigned A> +void test_alignment_of() +{ + static_assert( std::alignment_of<T>::value == A, ""); + static_assert( std::alignment_of<const T>::value == A, ""); + static_assert( std::alignment_of<volatile T>::value == A, ""); + static_assert( std::alignment_of<const volatile T>::value == A, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_alignment_of<int&, 4>(); + test_alignment_of<Class, 1>(); + test_alignment_of<int*, sizeof(intptr_t)>(); + test_alignment_of<const int*, sizeof(intptr_t)>(); + test_alignment_of<char[3], 1>(); + test_alignment_of<int, 4>(); + test_alignment_of<double, 8>(); +#if (defined(__ppc__) && !defined(__ppc64__)) + test_alignment_of<bool, 4>(); // 32-bit PPC has four byte bool +#else + test_alignment_of<bool, 1>(); +#endif + test_alignment_of<unsigned, 4>(); +} diff --git a/test/std/utilities/meta/meta.unary.prop.query/extent.pass.cpp b/test/std/utilities/meta/meta.unary.prop.query/extent.pass.cpp new file mode 100644 index 0000000000000..a99dc69485296 --- /dev/null +++ b/test/std/utilities/meta/meta.unary.prop.query/extent.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// extent + +#include <type_traits> + +template <class T, unsigned A> +void test_extent() +{ + static_assert((std::extent<T>::value == A), ""); + static_assert((std::extent<const T>::value == A), ""); + static_assert((std::extent<volatile T>::value == A), ""); + static_assert((std::extent<const volatile T>::value == A), ""); +} + +template <class T, unsigned A> +void test_extent1() +{ + static_assert((std::extent<T, 1>::value == A), ""); + static_assert((std::extent<const T, 1>::value == A), ""); + static_assert((std::extent<volatile T, 1>::value == A), ""); + static_assert((std::extent<const volatile T, 1>::value == A), ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_extent<void, 0>(); + test_extent<int&, 0>(); + test_extent<Class, 0>(); + test_extent<int*, 0>(); + test_extent<const int*, 0>(); + test_extent<int, 0>(); + test_extent<double, 0>(); + test_extent<bool, 0>(); + test_extent<unsigned, 0>(); + + test_extent<int[2], 2>(); + test_extent<int[2][4], 2>(); + test_extent<int[][4], 0>(); + + test_extent1<int, 0>(); + test_extent1<int[2], 0>(); + test_extent1<int[2][4], 4>(); + test_extent1<int[][4], 4>(); +} diff --git a/test/std/utilities/meta/meta.unary.prop.query/rank.pass.cpp b/test/std/utilities/meta/meta.unary.prop.query/rank.pass.cpp new file mode 100644 index 0000000000000..06f66a92c7c3b --- /dev/null +++ b/test/std/utilities/meta/meta.unary.prop.query/rank.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rank + +#include <type_traits> + +template <class T, unsigned A> +void test_rank() +{ + static_assert( std::rank<T>::value == A, ""); + static_assert( std::rank<const T>::value == A, ""); + static_assert( std::rank<volatile T>::value == A, ""); + static_assert( std::rank<const volatile T>::value == A, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_rank<void, 0>(); + test_rank<int&, 0>(); + test_rank<Class, 0>(); + test_rank<int*, 0>(); + test_rank<const int*, 0>(); + test_rank<int, 0>(); + test_rank<double, 0>(); + test_rank<bool, 0>(); + test_rank<unsigned, 0>(); + + test_rank<char[3], 1>(); + test_rank<char[][3], 2>(); + test_rank<char[][4][3], 3>(); +} diff --git a/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp b/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp new file mode 100644 index 0000000000000..5deeeff110d40 --- /dev/null +++ b/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// void_t + +#include <type_traits> + +#if _LIBCPP_STD_VER <= 14 +int main () {} +#else + +template <class T> +void test1() +{ + static_assert( std::is_same<void, std::void_t<T>>::value, ""); + static_assert( std::is_same<void, std::void_t<const T>>::value, ""); + static_assert( std::is_same<void, std::void_t<volatile T>>::value, ""); + static_assert( std::is_same<void, std::void_t<const volatile T>>::value, ""); +} + +template <class T, class U> +void test2() +{ + static_assert( std::is_same<void, std::void_t<T, U>>::value, ""); + static_assert( std::is_same<void, std::void_t<const T, U>>::value, ""); + static_assert( std::is_same<void, std::void_t<volatile T, U>>::value, ""); + static_assert( std::is_same<void, std::void_t<const volatile T, U>>::value, ""); + + static_assert( std::is_same<void, std::void_t<T, const U>>::value, ""); + static_assert( std::is_same<void, std::void_t<const T, const U>>::value, ""); + static_assert( std::is_same<void, std::void_t<volatile T, const U>>::value, ""); + static_assert( std::is_same<void, std::void_t<const volatile T, const U>>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + static_assert( std::is_same<void, std::void_t<>>::value, ""); + + test1<void>(); + test1<int>(); + test1<double>(); + test1<int&>(); + test1<Class>(); + test1<Class[]>(); + test1<Class[5]>(); + + test2<void, int>(); + test2<double, int>(); + test2<int&, int>(); + test2<Class&, bool>(); + test2<void *, int&>(); + + static_assert( std::is_same<void, std::void_t<int, double const &, Class, volatile int[], void>>::value, ""); +} +#endif diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp new file mode 100644 index 0000000000000..f4dd356383af1 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/array.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// array + +#include <type_traits> + +template <class T> +void test_array_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert( std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_array() +{ + test_array_imp<T>(); + test_array_imp<const T>(); + test_array_imp<volatile T>(); + test_array_imp<const volatile T>(); +} + +typedef char array[3]; +typedef const char const_array[3]; +typedef char incomplete_array[]; + +int main() +{ + test_array<array>(); + test_array<const_array>(); + test_array<incomplete_array>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp new file mode 100644 index 0000000000000..ac5d6e5923117 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/class.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// class + +#include <type_traits> + +template <class T> +void test_class_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert( std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_class() +{ + test_class_imp<T>(); + test_class_imp<const T>(); + test_class_imp<volatile T>(); + test_class_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_class<Class>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp new file mode 100644 index 0000000000000..7c9c78fcf2b9d --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/enum.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enum + +#include <type_traits> + +template <class T> +void test_enum_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert( std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_enum() +{ + test_enum_imp<T>(); + test_enum_imp<const T>(); + test_enum_imp<volatile T>(); + test_enum_imp<const volatile T>(); +} + +enum Enum {zero, one}; + +int main() +{ + test_enum<Enum>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp new file mode 100644 index 0000000000000..286644960315f --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/floating_point.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// floating_point + +#include <type_traits> + +template <class T> +void test_floating_point_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert( std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_floating_point() +{ + test_floating_point_imp<T>(); + test_floating_point_imp<const T>(); + test_floating_point_imp<volatile T>(); + test_floating_point_imp<const volatile T>(); +} + +int main() +{ + test_floating_point<float>(); + test_floating_point<double>(); + test_floating_point<long double>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp new file mode 100644 index 0000000000000..b1df4f2d3f4cc --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/function.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// function + +#include <type_traits> + +using namespace std; + +class Class {}; + +enum Enum1 {}; +#if __cplusplus >= 201103L +enum class Enum2 : int {}; +#else +enum Enum2 {}; +#endif + +template <class T> +void test() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert( std::is_function<T>::value, ""); +} + +// Since we can't actually add the const volatile and ref qualifiers once +// later let's use a macro to do it. +#define TEST_REGULAR(...) \ + test<__VA_ARGS__>(); \ + test<__VA_ARGS__ const>(); \ + test<__VA_ARGS__ volatile>(); \ + test<__VA_ARGS__ const volatile>() + + +#define TEST_REF_QUALIFIED(...) \ + test<__VA_ARGS__ &>(); \ + test<__VA_ARGS__ const &>(); \ + test<__VA_ARGS__ volatile &>(); \ + test<__VA_ARGS__ const volatile &>(); \ + test<__VA_ARGS__ &&>(); \ + test<__VA_ARGS__ const &&>(); \ + test<__VA_ARGS__ volatile &&>(); \ + test<__VA_ARGS__ const volatile &&>() + + +int main() +{ + TEST_REGULAR( void () ); + TEST_REGULAR( void (int) ); + TEST_REGULAR( int (double) ); + TEST_REGULAR( int (double, char) ); + TEST_REGULAR( void (...) ); + TEST_REGULAR( void (int, ...) ); + TEST_REGULAR( int (double, ...) ); + TEST_REGULAR( int (double, char, ...) ); +#if __cplusplus >= 201103L + TEST_REF_QUALIFIED( void () ); + TEST_REF_QUALIFIED( void (int) ); + TEST_REF_QUALIFIED( int (double) ); + TEST_REF_QUALIFIED( int (double, char) ); + TEST_REF_QUALIFIED( void (...) ); + TEST_REF_QUALIFIED( void (int, ...) ); + TEST_REF_QUALIFIED( int (double, ...) ); + TEST_REF_QUALIFIED( int (double, char, ...) ); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp new file mode 100644 index 0000000000000..f68ed3ef7e57e --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral + +#include <type_traits> + +template <class T> +void test_integral_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert( std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_integral() +{ + test_integral_imp<T>(); + test_integral_imp<const T>(); + test_integral_imp<volatile T>(); + test_integral_imp<const volatile T>(); +} + +int main() +{ + test_integral<bool>(); + test_integral<char>(); + test_integral<signed char>(); + test_integral<unsigned char>(); + test_integral<wchar_t>(); + test_integral<short>(); + test_integral<unsigned short>(); + test_integral<int>(); + test_integral<unsigned int>(); + test_integral<long>(); + test_integral<unsigned long>(); + test_integral<long long>(); + test_integral<unsigned long long>(); +#ifndef _LIBCPP_HAS_NO_INT128 + test_integral<__int128_t>(); + test_integral<__uint128_t>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp new file mode 100644 index 0000000000000..3b6ccade7e742 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/lvalue_ref.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// lvalue_ref + +#include <type_traits> + +template <class T> +void test_lvalue_ref() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert( std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +int main() +{ + test_lvalue_ref<int&>(); + test_lvalue_ref<const int&>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp new file mode 100644 index 0000000000000..6f546efdf51e1 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp @@ -0,0 +1,136 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_function_pointer + +#include <type_traits> +#include "test_macros.h" + +template <class T> +void test_member_function_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if TEST_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert( std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_member_function_pointer() +{ + test_member_function_pointer_imp<T>(); + test_member_function_pointer_imp<const T>(); + test_member_function_pointer_imp<volatile T>(); + test_member_function_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); + + test_member_function_pointer<void (Class::*)() const>(); + test_member_function_pointer<void (Class::*)(int) const>(); + test_member_function_pointer<void (Class::*)(int, char) const>(); + + test_member_function_pointer<void (Class::*)() volatile>(); + test_member_function_pointer<void (Class::*)(int) volatile>(); + test_member_function_pointer<void (Class::*)(int, char) volatile>(); + + test_member_function_pointer<void (Class::*)(...)>(); + test_member_function_pointer<void (Class::*)(int, ...)>(); + test_member_function_pointer<void (Class::*)(int, char, ...)>(); + + test_member_function_pointer<void (Class::*)(...) const>(); + test_member_function_pointer<void (Class::*)(int, ...) const>(); + test_member_function_pointer<void (Class::*)(int, char, ...) const>(); + + test_member_function_pointer<void (Class::*)(...) volatile>(); + test_member_function_pointer<void (Class::*)(int, ...) volatile>(); + test_member_function_pointer<void (Class::*)(int, char, ...) volatile>(); + +// reference qualifiers on functions are a C++11 extension +#if TEST_STD_VER >= 11 + test_member_function_pointer<void (Class::*)() &>(); + test_member_function_pointer<void (Class::*)(int) &>(); + test_member_function_pointer<void (Class::*)(int, char) &>(); + test_member_function_pointer<void (Class::*)(...) &>(); + test_member_function_pointer<void (Class::*)(int,...) &>(); + test_member_function_pointer<void (Class::*)(int, char,...) &>(); + + test_member_function_pointer<void (Class::*)() const &>(); + test_member_function_pointer<void (Class::*)(int) const &>(); + test_member_function_pointer<void (Class::*)(int, char) const &>(); + test_member_function_pointer<void (Class::*)(...) const &>(); + test_member_function_pointer<void (Class::*)(int,...) const &>(); + test_member_function_pointer<void (Class::*)(int, char,...) const &>(); + + test_member_function_pointer<void (Class::*)() volatile &>(); + test_member_function_pointer<void (Class::*)(int) volatile &>(); + test_member_function_pointer<void (Class::*)(int, char) volatile &>(); + test_member_function_pointer<void (Class::*)(...) volatile &>(); + test_member_function_pointer<void (Class::*)(int,...) volatile &>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile &>(); + + test_member_function_pointer<void (Class::*)() const volatile &>(); + test_member_function_pointer<void (Class::*)(int) const volatile &>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile &>(); + test_member_function_pointer<void (Class::*)(...) const volatile &>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile &>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>(); + + // RValue qualifiers + test_member_function_pointer<void (Class::*)() &&>(); + test_member_function_pointer<void (Class::*)(int) &&>(); + test_member_function_pointer<void (Class::*)(int, char) &&>(); + test_member_function_pointer<void (Class::*)(...) &&>(); + test_member_function_pointer<void (Class::*)(int,...) &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) &&>(); + + test_member_function_pointer<void (Class::*)() const &&>(); + test_member_function_pointer<void (Class::*)(int) const &&>(); + test_member_function_pointer<void (Class::*)(int, char) const &&>(); + test_member_function_pointer<void (Class::*)(...) const &&>(); + test_member_function_pointer<void (Class::*)(int,...) const &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) const &&>(); + + test_member_function_pointer<void (Class::*)() volatile &&>(); + test_member_function_pointer<void (Class::*)(int) volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char) volatile &&>(); + test_member_function_pointer<void (Class::*)(...) volatile &&>(); + test_member_function_pointer<void (Class::*)(int,...) volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>(); + + test_member_function_pointer<void (Class::*)() const volatile &&>(); + test_member_function_pointer<void (Class::*)(int) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile &&>(); + test_member_function_pointer<void (Class::*)(...) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer_no_variadics.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer_no_variadics.pass.cpp new file mode 100644 index 0000000000000..e13e58632a325 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer_no_variadics.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_function_pointer + +#define _LIBCPP_HAS_NO_VARIADICS +#include <type_traits> + +template <class T> +void test_member_function_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert( std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_member_function_pointer() +{ + test_member_function_pointer_imp<T>(); + test_member_function_pointer_imp<const T>(); + test_member_function_pointer_imp<volatile T>(); + test_member_function_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); + + test_member_function_pointer<void (Class::*)() const>(); + test_member_function_pointer<void (Class::*)(int) const>(); + test_member_function_pointer<void (Class::*)(int, char) const>(); + + test_member_function_pointer<void (Class::*)() volatile>(); + test_member_function_pointer<void (Class::*)(int) volatile>(); + test_member_function_pointer<void (Class::*)(int, char) volatile>(); + + test_member_function_pointer<void (Class::*)(...)>(); + test_member_function_pointer<void (Class::*)(int, ...)>(); + test_member_function_pointer<void (Class::*)(int, char, ...)>(); + + test_member_function_pointer<void (Class::*)(...) const>(); + test_member_function_pointer<void (Class::*)(int, ...) const>(); + test_member_function_pointer<void (Class::*)(int, char, ...) const>(); + + test_member_function_pointer<void (Class::*)(...) volatile>(); + test_member_function_pointer<void (Class::*)(int, ...) volatile>(); + test_member_function_pointer<void (Class::*)(int, char, ...) volatile>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp new file mode 100644 index 0000000000000..4e6699cc3e7c0 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_object_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_object_pointer + +#include <type_traits> + +template <class T> +void test_member_object_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert( std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_member_object_pointer() +{ + test_member_object_pointer_imp<T>(); + test_member_object_pointer_imp<const T>(); + test_member_object_pointer_imp<volatile T>(); + test_member_object_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_object_pointer<int Class::*>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/nullptr.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/nullptr.pass.cpp new file mode 100644 index 0000000000000..691e3536167d0 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/nullptr.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// nullptr_t +// is_null_pointer + +#include <type_traits> + +#if _LIBCPP_STD_VER > 11 +template <class T> +void test_nullptr_imp() +{ + static_assert(!std::is_void<T>::value, ""); + static_assert( std::is_null_pointer<T>::value, ""); + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_nullptr() +{ + test_nullptr_imp<T>(); + test_nullptr_imp<const T>(); + test_nullptr_imp<volatile T>(); + test_nullptr_imp<const volatile T>(); +} + +int main() +{ + test_nullptr<std::nullptr_t>(); +} +#else +int main() {} +#endif diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp new file mode 100644 index 0000000000000..7073c106b44b7 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// pointer + +#include <type_traits> + +template <class T> +void test_pointer_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert( std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_pointer() +{ + test_pointer_imp<T>(); + test_pointer_imp<const T>(); + test_pointer_imp<volatile T>(); + test_pointer_imp<const volatile T>(); +} + +int main() +{ + test_pointer<void*>(); + test_pointer<int*>(); + test_pointer<const int*>(); + test_pointer<void (*)(int)>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp new file mode 100644 index 0000000000000..7964424036348 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/rvalue_ref.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rvalue_ref + +#include <type_traits> + +template <class T> +void test_rvalue_ref() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert( std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_rvalue_ref<int&&>(); + test_rvalue_ref<const int&&>(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp new file mode 100644 index 0000000000000..6cabb717c0c68 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/union.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// union + +#include <type_traits> + +template <class T> +void test_union_imp() +{ + static_assert(!std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert( std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_union() +{ + test_union_imp<T>(); + test_union_imp<const T>(); + test_union_imp<volatile T>(); + test_union_imp<const volatile T>(); +} + +union Union +{ + int _; + double __; +}; + +int main() +{ + test_union<Union>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp new file mode 100644 index 0000000000000..f20bcf87ea150 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/void.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// void + +#include <type_traits> + +template <class T> +void test_void_imp() +{ + static_assert( std::is_void<T>::value, ""); +#if _LIBCPP_STD_VER > 11 + static_assert(!std::is_null_pointer<T>::value, ""); +#endif + static_assert(!std::is_integral<T>::value, ""); + static_assert(!std::is_floating_point<T>::value, ""); + static_assert(!std::is_array<T>::value, ""); + static_assert(!std::is_pointer<T>::value, ""); + static_assert(!std::is_lvalue_reference<T>::value, ""); + static_assert(!std::is_rvalue_reference<T>::value, ""); + static_assert(!std::is_member_object_pointer<T>::value, ""); + static_assert(!std::is_member_function_pointer<T>::value, ""); + static_assert(!std::is_enum<T>::value, ""); + static_assert(!std::is_union<T>::value, ""); + static_assert(!std::is_class<T>::value, ""); + static_assert(!std::is_function<T>::value, ""); +} + +template <class T> +void test_void() +{ + test_void_imp<T>(); + test_void_imp<const T>(); + test_void_imp<volatile T>(); + test_void_imp<const volatile T>(); +} + +int main() +{ + test_void<void>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp new file mode 100644 index 0000000000000..3476d5ceea2ba --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/array.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// array + +#include <type_traits> + +template <class T> +void test_array_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_array() +{ + test_array_imp<T>(); + test_array_imp<const T>(); + test_array_imp<volatile T>(); + test_array_imp<const volatile T>(); +} + +typedef char array[3]; +typedef const char const_array[3]; +typedef char incomplete_array[]; + +int main() +{ + test_array<array>(); + test_array<const_array>(); + test_array<incomplete_array>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp new file mode 100644 index 0000000000000..49e41380ca273 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/class.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// class + +#include <type_traits> + +template <class T> +void test_class_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_class() +{ + test_class_imp<T>(); + test_class_imp<const T>(); + test_class_imp<volatile T>(); + test_class_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_class<Class>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp new file mode 100644 index 0000000000000..dc9e4874ab190 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/enum.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// enum + +#include <type_traits> + +template <class T> +void test_enum_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_enum() +{ + test_enum_imp<T>(); + test_enum_imp<const T>(); + test_enum_imp<volatile T>(); + test_enum_imp<const volatile T>(); +} + +enum Enum {zero, one}; + +int main() +{ + test_enum<Enum>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp new file mode 100644 index 0000000000000..3560b456b0048 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/floating_point.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// floating_point + +#include <type_traits> + +template <class T> +void test_floating_point_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert( std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_floating_point() +{ + test_floating_point_imp<T>(); + test_floating_point_imp<const T>(); + test_floating_point_imp<volatile T>(); + test_floating_point_imp<const volatile T>(); +} + +int main() +{ + test_floating_point<float>(); + test_floating_point<double>(); + test_floating_point<long double>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp new file mode 100644 index 0000000000000..fc8a1e5a8b26b --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/function.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// function + +#include <type_traits> + +template <class T> +void test_function_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_function() +{ + test_function_imp<T>(); + test_function_imp<const T>(); + test_function_imp<volatile T>(); + test_function_imp<const volatile T>(); +} + +int main() +{ + test_function<void ()>(); + test_function<void (int)>(); + test_function<int (double)>(); + test_function<int (double, char)>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp new file mode 100644 index 0000000000000..0bc94583ab04c --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// integral + +#include <type_traits> + +template <class T> +void test_integral_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert( std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_integral() +{ + test_integral_imp<T>(); + test_integral_imp<const T>(); + test_integral_imp<volatile T>(); + test_integral_imp<const volatile T>(); +} + +int main() +{ + test_integral<bool>(); + test_integral<char>(); + test_integral<signed char>(); + test_integral<unsigned char>(); + test_integral<wchar_t>(); + test_integral<short>(); + test_integral<unsigned short>(); + test_integral<int>(); + test_integral<unsigned int>(); + test_integral<long>(); + test_integral<unsigned long>(); + test_integral<long long>(); + test_integral<unsigned long long>(); +#ifndef _LIBCPP_HAS_NO_INT128 + test_integral<__int128_t>(); + test_integral<__uint128_t>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp new file mode 100644 index 0000000000000..dd812832f6cf6 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/lvalue_ref.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// lvalue_ref + +#include <type_traits> + +template <class T> +void test_lvalue_ref() +{ + static_assert( std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +int main() +{ + test_lvalue_ref<int&>(); + test_lvalue_ref<const int&>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp new file mode 100644 index 0000000000000..0df21173c6918 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/member_function_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_function_pointer + +#include <type_traits> + +template <class T> +void test_member_function_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert( std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_member_function_pointer() +{ + test_member_function_pointer_imp<T>(); + test_member_function_pointer_imp<const T>(); + test_member_function_pointer_imp<volatile T>(); + test_member_function_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp new file mode 100644 index 0000000000000..a0dea4a9c44fb --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/member_object_pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// member_object_pointer + +#include <type_traits> + +template <class T> +void test_member_object_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert( std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_member_object_pointer() +{ + test_member_object_pointer_imp<T>(); + test_member_object_pointer_imp<const T>(); + test_member_object_pointer_imp<volatile T>(); + test_member_object_pointer_imp<const volatile T>(); +} + +class Class +{ +}; + +int main() +{ + test_member_object_pointer<int Class::*>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp new file mode 100644 index 0000000000000..de23da83637a8 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/pointer.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// pointer + +#include <type_traits> + +template <class T> +void test_pointer_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert( std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_pointer() +{ + test_pointer_imp<T>(); + test_pointer_imp<const T>(); + test_pointer_imp<volatile T>(); + test_pointer_imp<const volatile T>(); +} + +int main() +{ + test_pointer<void*>(); + test_pointer<int*>(); + test_pointer<const int*>(); + test_pointer<void (*)(int)>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp new file mode 100644 index 0000000000000..7563c2fd58506 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/rvalue_ref.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// rvalue_ref + +#include <type_traits> + +template <class T> +void test_rvalue_ref() +{ + static_assert( std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_rvalue_ref<int&&>(); + test_rvalue_ref<const int&&>(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp new file mode 100644 index 0000000000000..05db74c8aaf54 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/union.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// union + +#include <type_traits> + +template <class T> +void test_union_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert(!std::is_fundamental<T>::value, ""); + static_assert( std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert( std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_union() +{ + test_union_imp<T>(); + test_union_imp<const T>(); + test_union_imp<volatile T>(); + test_union_imp<const volatile T>(); +} + +union Union +{ + int _; + double __; +}; + +int main() +{ + test_union<Union>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp new file mode 100644 index 0000000000000..59569fe086bfe --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.comp/void.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// void + +#include <type_traits> + +template <class T> +void test_void_imp() +{ + static_assert(!std::is_reference<T>::value, ""); + static_assert(!std::is_arithmetic<T>::value, ""); + static_assert( std::is_fundamental<T>::value, ""); + static_assert(!std::is_object<T>::value, ""); + static_assert(!std::is_scalar<T>::value, ""); + static_assert(!std::is_compound<T>::value, ""); + static_assert(!std::is_member_pointer<T>::value, ""); +} + +template <class T> +void test_void() +{ + test_void_imp<T>(); + test_void_imp<const T>(); + test_void_imp<volatile T>(); + test_void_imp<const volatile T>(); +} + +int main() +{ + test_void<void>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp new file mode 100644 index 0000000000000..1c715e04970c7 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/__has_operator_addressof.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// extension + +// template <typename _Tp> struct __has_operator_addressof + + +#include <type_traits> + +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + +struct A +{ +}; + +struct B +{ + constexpr B* operator&() const; +}; + +struct D; + +struct C +{ + template <class U> + D operator,(U&&); +}; + +struct E +{ + constexpr C operator&() const; +}; + +struct F {}; +constexpr F* operator&(F const &) { return nullptr; } + +struct G {}; +constexpr G* operator&(G &&) { return nullptr; } + +struct H {}; +constexpr H* operator&(H const &&) { return nullptr; } + +struct J +{ + constexpr J* operator&() const &&; +}; + +#endif // _LIBCPP_HAS_NO_CONSTEXPR + +int main() +{ +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::__has_operator_addressof<int>::value == false, ""); + static_assert(std::__has_operator_addressof<A>::value == false, ""); + static_assert(std::__has_operator_addressof<B>::value == true, ""); + static_assert(std::__has_operator_addressof<E>::value == true, ""); + static_assert(std::__has_operator_addressof<F>::value == true, ""); + static_assert(std::__has_operator_addressof<G>::value == true, ""); + static_assert(std::__has_operator_addressof<H>::value == true, ""); + static_assert(std::__has_operator_addressof<J>::value == true, ""); +#endif // _LIBCPP_HAS_NO_CONSTEXPR +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp new file mode 100644 index 0000000000000..685d30de692f2 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/has_virtual_destructor.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_virtual_destructor + +#include <type_traits> + +template <class T> +void test_has_virtual_destructor() +{ + static_assert( std::has_virtual_destructor<T>::value, ""); + static_assert( std::has_virtual_destructor<const T>::value, ""); + static_assert( std::has_virtual_destructor<volatile T>::value, ""); + static_assert( std::has_virtual_destructor<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_virtual_destructor() +{ + static_assert(!std::has_virtual_destructor<T>::value, ""); + static_assert(!std::has_virtual_destructor<const T>::value, ""); + static_assert(!std::has_virtual_destructor<volatile T>::value, ""); + static_assert(!std::has_virtual_destructor<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + ~A(); +}; + +int main() +{ + test_has_not_virtual_destructor<void>(); + test_has_not_virtual_destructor<A>(); + test_has_not_virtual_destructor<int&>(); + test_has_not_virtual_destructor<Union>(); + test_has_not_virtual_destructor<Empty>(); + test_has_not_virtual_destructor<int>(); + test_has_not_virtual_destructor<double>(); + test_has_not_virtual_destructor<int*>(); + test_has_not_virtual_destructor<const int*>(); + test_has_not_virtual_destructor<char[3]>(); + test_has_not_virtual_destructor<char[]>(); + test_has_not_virtual_destructor<bit_zero>(); + + test_has_virtual_destructor<Abstract>(); + test_has_virtual_destructor<NotEmpty>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp new file mode 100644 index 0000000000000..f2a8c23246b18 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_abstract + +#include <type_traits> + +template <class T> +void test_is_abstract() +{ + static_assert( std::is_abstract<T>::value, ""); + static_assert( std::is_abstract<const T>::value, ""); + static_assert( std::is_abstract<volatile T>::value, ""); + static_assert( std::is_abstract<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_abstract() +{ + static_assert(!std::is_abstract<T>::value, ""); + static_assert(!std::is_abstract<const T>::value, ""); + static_assert(!std::is_abstract<volatile T>::value, ""); + static_assert(!std::is_abstract<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +int main() +{ + test_is_not_abstract<void>(); + test_is_not_abstract<int&>(); + test_is_not_abstract<int>(); + test_is_not_abstract<double>(); + test_is_not_abstract<int*>(); + test_is_not_abstract<const int*>(); + test_is_not_abstract<char[3]>(); + test_is_not_abstract<char[]>(); + test_is_not_abstract<Union>(); + test_is_not_abstract<Empty>(); + test_is_not_abstract<bit_zero>(); + test_is_not_abstract<NotEmpty>(); + + test_is_abstract<Abstract>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp new file mode 100644 index 0000000000000..d33019bcba9ec --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_assignable + +#include <type_traits> + +struct A +{ +}; + +struct B +{ + void operator=(A); +}; + +template <class T, class U> +void test_is_assignable() +{ + static_assert(( std::is_assignable<T, U>::value), ""); +} + +template <class T, class U> +void test_is_not_assignable() +{ + static_assert((!std::is_assignable<T, U>::value), ""); +} + +struct D; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +struct C +{ + template <class U> + D operator,(U&&); +}; + +struct E +{ + C operator=(int); +}; +#endif + +template <typename T> +struct X { T t; }; + +int main() +{ + test_is_assignable<int&, int&> (); + test_is_assignable<int&, int> (); + test_is_assignable<int&, double> (); + test_is_assignable<B, A> (); + test_is_assignable<void*&, void*> (); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_is_assignable<E, int> (); + + test_is_not_assignable<int, int&> (); + test_is_not_assignable<int, int> (); +#endif + test_is_not_assignable<A, B> (); + test_is_not_assignable<void, const void> (); + test_is_not_assignable<const void, const void> (); + test_is_not_assignable<int(), int> (); + +// pointer to incomplete template type + test_is_assignable<X<D>*&, X<D>*> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp new file mode 100644 index 0000000000000..72f2ff458921a --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_const.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_const + +#include <type_traits> + +template <class T> +void test_is_const() +{ + static_assert(!std::is_const<T>::value, ""); + static_assert( std::is_const<const T>::value, ""); + static_assert(!std::is_const<volatile T>::value, ""); + static_assert( std::is_const<const volatile T>::value, ""); +} + +int main() +{ + test_is_const<void>(); + test_is_const<int>(); + test_is_const<double>(); + test_is_const<int*>(); + test_is_const<const int*>(); + test_is_const<char[3]>(); + test_is_const<char[]>(); + + static_assert(!std::is_const<int&>::value, ""); + static_assert(!std::is_const<const int&>::value, ""); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp new file mode 100644 index 0000000000000..2b8f7efec6027 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// template <class T, class... Args> +// struct is_constructible; + +#include <type_traits> + +struct A +{ + explicit A(int); + A(int, double); +#if __has_feature(cxx_access_control_sfinae) +private: +#endif + A(char); +}; + +class Abstract +{ + virtual void foo() = 0; +}; + +class AbstractDestructor +{ + virtual ~AbstractDestructor() = 0; +}; + +template <class T> +void test_is_constructible() +{ + static_assert( (std::is_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_constructible() +{ + static_assert( (std::is_constructible<T, A0>::value), ""); +} + +template <class T, class A0, class A1> +void test_is_constructible() +{ + static_assert( (std::is_constructible<T, A0, A1>::value), ""); +} + +template <class T> +void test_is_not_constructible() +{ + static_assert((!std::is_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_not_constructible() +{ + static_assert((!std::is_constructible<T, A0>::value), ""); +} + +int main() +{ + test_is_constructible<int> (); + test_is_constructible<int, const int> (); + test_is_constructible<A, int> (); + test_is_constructible<A, int, double> (); + test_is_constructible<int&, int&> (); + + test_is_not_constructible<A> (); +#if __has_feature(cxx_access_control_sfinae) + test_is_not_constructible<A, char> (); +#else + test_is_constructible<A, char> (); +#endif + test_is_not_constructible<A, void> (); + test_is_not_constructible<void> (); + test_is_not_constructible<int&> (); + test_is_not_constructible<Abstract> (); + test_is_not_constructible<AbstractDestructor> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp new file mode 100644 index 0000000000000..c43d59479fb28 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_assignable.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_copy_assignable + +#include <type_traits> + +template <class T> +void test_is_copy_assignable() +{ + static_assert(( std::is_copy_assignable<T>::value), ""); +} + +template <class T> +void test_is_not_copy_assignable() +{ + static_assert((!std::is_copy_assignable<T>::value), ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A(); +}; + +class B +{ + B& operator=(const B&); +}; + +struct C +{ + void operator=(C&); // not const +}; + +int main() +{ + test_is_copy_assignable<int> (); + test_is_copy_assignable<int&> (); + test_is_copy_assignable<A> (); + test_is_copy_assignable<bit_zero> (); + test_is_copy_assignable<Union> (); + test_is_copy_assignable<NotEmpty> (); + test_is_copy_assignable<Empty> (); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_is_not_copy_assignable<const int> (); + test_is_not_copy_assignable<int[]> (); + test_is_not_copy_assignable<int[3]> (); +#endif +#if __has_feature(cxx_access_control_sfinae) + test_is_not_copy_assignable<B> (); +#endif + test_is_not_copy_assignable<void> (); + test_is_not_copy_assignable<C> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp new file mode 100644 index 0000000000000..f878a50c3af5c --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_copy_constructible.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_copy_constructible + +#include <type_traits> + +template <class T> +void test_is_copy_constructible() +{ + static_assert( std::is_copy_constructible<T>::value, ""); +} + +template <class T> +void test_is_not_copy_constructible() +{ + static_assert(!std::is_copy_constructible<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ +public: + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +class B +{ + B(const B&); +}; + +struct C +{ + C(C&); // not const + void operator=(C&); // not const +}; + +int main() +{ + test_is_copy_constructible<A>(); + test_is_copy_constructible<int&>(); + test_is_copy_constructible<Union>(); + test_is_copy_constructible<Empty>(); + test_is_copy_constructible<int>(); + test_is_copy_constructible<double>(); + test_is_copy_constructible<int*>(); + test_is_copy_constructible<const int*>(); + test_is_copy_constructible<NotEmpty>(); + test_is_copy_constructible<bit_zero>(); + + test_is_not_copy_constructible<char[3]>(); + test_is_not_copy_constructible<char[]>(); + test_is_not_copy_constructible<void>(); + test_is_not_copy_constructible<Abstract>(); + test_is_not_copy_constructible<C>(); +#if __has_feature(cxx_access_control_sfinae) + test_is_not_copy_constructible<B>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_default_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_default_constructible.pass.cpp new file mode 100644 index 0000000000000..c8d5c42fbf89d --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_default_constructible.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_default_constructible + +#include <type_traits> + +template <class T> +void test_is_default_constructible() +{ + static_assert( std::is_default_constructible<T>::value, ""); + static_assert( std::is_default_constructible<const T>::value, ""); + static_assert( std::is_default_constructible<volatile T>::value, ""); + static_assert( std::is_default_constructible<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_default_constructible() +{ + static_assert(!std::is_default_constructible<T>::value, ""); + static_assert(!std::is_default_constructible<const T>::value, ""); + static_assert(!std::is_default_constructible<volatile T>::value, ""); + static_assert(!std::is_default_constructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NoDefaultConstructor +{ + NoDefaultConstructor(int) {} +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ +public: + virtual ~Abstract() = 0; +}; + +struct A +{ + A(); +}; + +class B +{ + B(); +}; + +int main() +{ + test_is_default_constructible<A>(); + test_is_default_constructible<Union>(); + test_is_default_constructible<Empty>(); + test_is_default_constructible<int>(); + test_is_default_constructible<double>(); + test_is_default_constructible<int*>(); + test_is_default_constructible<const int*>(); + test_is_default_constructible<char[3]>(); + test_is_default_constructible<NotEmpty>(); + test_is_default_constructible<bit_zero>(); + + test_is_not_default_constructible<void>(); + test_is_not_default_constructible<int&>(); + test_is_not_default_constructible<char[]>(); + test_is_not_default_constructible<Abstract>(); + test_is_not_default_constructible<NoDefaultConstructor>(); +#if __has_feature(cxx_access_control_sfinae) + test_is_not_default_constructible<B>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp new file mode 100644 index 0000000000000..807745ef66c16 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_destructible.pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_destructible + +#include <type_traits> + +template <class T> +void test_is_destructible() +{ + static_assert( std::is_destructible<T>::value, ""); + static_assert( std::is_destructible<const T>::value, ""); + static_assert( std::is_destructible<volatile T>::value, ""); + static_assert( std::is_destructible<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_destructible() +{ + static_assert(!std::is_destructible<T>::value, ""); + static_assert(!std::is_destructible<const T>::value, ""); + static_assert(!std::is_destructible<volatile T>::value, ""); + static_assert(!std::is_destructible<const volatile T>::value, ""); +} + +class Empty {}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + ~A(); +}; + +typedef void (Function) (); + +struct PublicAbstract { public: virtual void foo() = 0; }; +struct ProtectedAbstract { protected: virtual void foo() = 0; }; +struct PrivateAbstract { private: virtual void foo() = 0; }; + +struct PublicDestructor { public: ~PublicDestructor() {}}; +struct ProtectedDestructor { protected: ~ProtectedDestructor() {}}; +struct PrivateDestructor { private: ~PrivateDestructor() {}}; + +struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}}; +struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}}; +struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}}; + +struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; }; +struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; }; +struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; }; + +struct DeletedPublicDestructor { public: ~DeletedPublicDestructor() = delete; }; +struct DeletedProtectedDestructor { protected: ~DeletedProtectedDestructor() = delete; }; +struct DeletedPrivateDestructor { private: ~DeletedPrivateDestructor() = delete; }; + +struct DeletedVirtualPublicDestructor { public: virtual ~DeletedVirtualPublicDestructor() = delete; }; +struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; }; +struct DeletedVirtualPrivateDestructor { private: virtual ~DeletedVirtualPrivateDestructor() = delete; }; + + +int main() +{ + test_is_destructible<A>(); + test_is_destructible<int&>(); + test_is_destructible<Union>(); + test_is_destructible<Empty>(); + test_is_destructible<int>(); + test_is_destructible<double>(); + test_is_destructible<int*>(); + test_is_destructible<const int*>(); + test_is_destructible<char[3]>(); + test_is_destructible<bit_zero>(); + test_is_destructible<int[3]>(); + test_is_destructible<ProtectedAbstract>(); + test_is_destructible<PublicAbstract>(); + test_is_destructible<PrivateAbstract>(); + test_is_destructible<PublicDestructor>(); + test_is_destructible<VirtualPublicDestructor>(); + test_is_destructible<PurePublicDestructor>(); + + test_is_not_destructible<int[]>(); + test_is_not_destructible<void>(); + + test_is_not_destructible<ProtectedDestructor>(); + test_is_not_destructible<PrivateDestructor>(); + test_is_not_destructible<VirtualProtectedDestructor>(); + test_is_not_destructible<VirtualPrivateDestructor>(); + test_is_not_destructible<PureProtectedDestructor>(); + test_is_not_destructible<PurePrivateDestructor>(); + test_is_not_destructible<DeletedPublicDestructor>(); + test_is_not_destructible<DeletedProtectedDestructor>(); + test_is_not_destructible<DeletedPrivateDestructor>(); + +// test_is_not_destructible<DeletedVirtualPublicDestructor>(); // currently fails due to clang bug #20268 + test_is_not_destructible<DeletedVirtualProtectedDestructor>(); + test_is_not_destructible<DeletedVirtualPrivateDestructor>(); + +#if __has_feature(cxx_access_control_sfinae) + test_is_not_destructible<NotEmpty>(); +#endif + test_is_not_destructible<Function>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp new file mode 100644 index 0000000000000..47af3c45cdea9 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_empty + +#include <type_traits> + +template <class T> +void test_is_empty() +{ + static_assert( std::is_empty<T>::value, ""); + static_assert( std::is_empty<const T>::value, ""); + static_assert( std::is_empty<volatile T>::value, ""); + static_assert( std::is_empty<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_empty() +{ + static_assert(!std::is_empty<T>::value, ""); + static_assert(!std::is_empty<const T>::value, ""); + static_assert(!std::is_empty<volatile T>::value, ""); + static_assert(!std::is_empty<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +int main() +{ + test_is_not_empty<void>(); + test_is_not_empty<int&>(); + test_is_not_empty<int>(); + test_is_not_empty<double>(); + test_is_not_empty<int*>(); + test_is_not_empty<const int*>(); + test_is_not_empty<char[3]>(); + test_is_not_empty<char[]>(); + test_is_not_empty<Union>(); + test_is_not_empty<NotEmpty>(); + + test_is_empty<Empty>(); + test_is_empty<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_final.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_final.pass.cpp new file mode 100644 index 0000000000000..cf32196213e16 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_final.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_final + +#include <type_traits> + +#if _LIBCPP_STD_VER > 11 + +struct P final { }; +union U1 { }; +union U2 final { }; + +template <class T> +void test_is_final() +{ + static_assert( std::is_final<T>::value, ""); + static_assert( std::is_final<const T>::value, ""); + static_assert( std::is_final<volatile T>::value, ""); + static_assert( std::is_final<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_final() +{ + static_assert(!std::is_final<T>::value, ""); + static_assert(!std::is_final<const T>::value, ""); + static_assert(!std::is_final<volatile T>::value, ""); + static_assert(!std::is_final<const volatile T>::value, ""); +} + +int main () +{ + test_is_not_final<int>(); + test_is_not_final<int*>(); + test_is_final <P>(); + test_is_not_final<P*>(); + test_is_not_final<U1>(); + test_is_not_final<U1*>(); + test_is_final <U2>(); + test_is_not_final<U2*>(); +} +#else +int main () {} +#endif diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp new file mode 100644 index 0000000000000..ce781cd936b02 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_literal_type + +#include <type_traits> + +template <class T> +void test_is_literal_type() +{ + static_assert( std::is_literal_type<T>::value, ""); +} + +template <class T> +void test_is_not_literal_type() +{ + static_assert(!std::is_literal_type<T>::value, ""); +} + +struct A +{ +}; + +struct B +{ + B(); +}; + +int main() +{ + test_is_literal_type<int> (); + test_is_literal_type<const int> (); + test_is_literal_type<int&> (); + test_is_literal_type<volatile int&> (); + test_is_literal_type<A> (); + + test_is_not_literal_type<B> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_assignable.pass.cpp new file mode 100644 index 0000000000000..a89ee7d4e4903 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_move_assignable + +#include <type_traits> + +template <class T> +void test_is_move_assignable() +{ + static_assert( std::is_move_assignable<T>::value, ""); +} + +template <class T> +void test_is_not_move_assignable() +{ + static_assert(!std::is_move_assignable<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A(); +}; + +int main() +{ + test_is_move_assignable<int> (); + test_is_move_assignable<A> (); + test_is_move_assignable<bit_zero> (); + test_is_move_assignable<Union> (); + test_is_move_assignable<NotEmpty> (); + test_is_move_assignable<Empty> (); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_is_not_move_assignable<const int> (); + test_is_not_move_assignable<int[]> (); + test_is_not_move_assignable<int[3]> (); +#endif + test_is_not_move_assignable<void> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_constructible.pass.cpp new file mode 100644 index 0000000000000..7409ebaa56c8f --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_move_constructible.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_move_constructible + +#include <type_traits> + +template <class T> +void test_is_move_constructible() +{ + static_assert( std::is_move_constructible<T>::value, ""); +} + +template <class T> +void test_is_not_move_constructible() +{ + static_assert(!std::is_move_constructible<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ +public: + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +struct B +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + B(B&&); +#endif +}; + +int main() +{ + test_is_not_move_constructible<char[3]>(); + test_is_not_move_constructible<char[]>(); + test_is_not_move_constructible<void>(); + test_is_not_move_constructible<Abstract>(); + + test_is_move_constructible<A>(); + test_is_move_constructible<int&>(); + test_is_move_constructible<Union>(); + test_is_move_constructible<Empty>(); + test_is_move_constructible<int>(); + test_is_move_constructible<double>(); + test_is_move_constructible<int*>(); + test_is_move_constructible<const int*>(); + test_is_move_constructible<NotEmpty>(); + test_is_move_constructible<bit_zero>(); + test_is_move_constructible<B>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp new file mode 100644 index 0000000000000..8fff5f8b3de3c --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_nothrow_assignable + +#include <type_traits> + +template <class T, class U> +void test_is_nothrow_assignable() +{ + static_assert(( std::is_nothrow_assignable<T, U>::value), ""); +} + +template <class T, class U> +void test_is_not_nothrow_assignable() +{ + static_assert((!std::is_nothrow_assignable<T, U>::value), ""); +} + +struct A +{ +}; + +struct B +{ + void operator=(A); +}; + +struct C +{ + void operator=(C&); // not const +}; + +int main() +{ + test_is_nothrow_assignable<int&, int&> (); + test_is_nothrow_assignable<int&, int> (); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_is_nothrow_assignable<int&, double> (); +#endif + + test_is_not_nothrow_assignable<int, int&> (); + test_is_not_nothrow_assignable<int, int> (); + test_is_not_nothrow_assignable<B, A> (); + test_is_not_nothrow_assignable<A, B> (); + test_is_not_nothrow_assignable<C, C&> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp new file mode 100644 index 0000000000000..fe0b5673bc44d --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_constructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// template <class T, class... Args> +// struct is_nothrow_constructible; + +#include <type_traits> + +template <class T> +void test_is_nothrow_constructible() +{ + static_assert(( std::is_nothrow_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_nothrow_constructible() +{ + static_assert(( std::is_nothrow_constructible<T, A0>::value), ""); +} + +template <class T> +void test_is_not_nothrow_constructible() +{ + static_assert((!std::is_nothrow_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_not_nothrow_constructible() +{ + static_assert((!std::is_nothrow_constructible<T, A0>::value), ""); +} + +template <class T, class A0, class A1> +void test_is_not_nothrow_constructible() +{ + static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +struct C +{ + C(C&); // not const + void operator=(C&); // not const +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +struct Tuple { + Tuple(Empty&&) noexcept {} +}; +#endif + +int main() +{ + test_is_nothrow_constructible<int> (); + test_is_nothrow_constructible<int, const int&> (); + test_is_nothrow_constructible<Empty> (); + test_is_nothrow_constructible<Empty, const Empty&> (); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_is_nothrow_constructible<Tuple &&, Empty> (); // See bug #19616. +#endif + + test_is_not_nothrow_constructible<A, int> (); + test_is_not_nothrow_constructible<A, int, double> (); + test_is_not_nothrow_constructible<A> (); + test_is_not_nothrow_constructible<C> (); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert(!std::is_constructible<Tuple&, Empty>::value, ""); + test_is_not_nothrow_constructible<Tuple &, Empty> (); // See bug #19616. +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_assignable.pass.cpp new file mode 100644 index 0000000000000..d843803cf21da --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_nothrow_copy_assignable + +#include <type_traits> + +template <class T> +void test_has_nothrow_assign() +{ + static_assert( std::is_nothrow_copy_assignable<T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_assign() +{ + static_assert(!std::is_nothrow_copy_assignable<T>::value, ""); +} + +class Empty +{ +}; + +struct NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_nothrow_assign<int&>(); + test_has_nothrow_assign<Union>(); + test_has_nothrow_assign<Empty>(); + test_has_nothrow_assign<int>(); + test_has_nothrow_assign<double>(); + test_has_nothrow_assign<int*>(); + test_has_nothrow_assign<const int*>(); + test_has_nothrow_assign<NotEmpty>(); + test_has_nothrow_assign<bit_zero>(); + + test_has_not_nothrow_assign<const int>(); + test_has_not_nothrow_assign<void>(); + test_has_not_nothrow_assign<A>(); + +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_constructible.pass.cpp new file mode 100644 index 0000000000000..99fce65dcc7e7 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_copy_constructible.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_nothrow_copy_constructible + +#include <type_traits> + +template <class T> +void test_is_nothrow_copy_constructible() +{ + static_assert( std::is_nothrow_copy_constructible<T>::value, ""); + static_assert( std::is_nothrow_copy_constructible<const T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_copy_constructor() +{ + static_assert(!std::is_nothrow_copy_constructible<T>::value, ""); + static_assert(!std::is_nothrow_copy_constructible<const T>::value, ""); + static_assert(!std::is_nothrow_copy_constructible<volatile T>::value, ""); + static_assert(!std::is_nothrow_copy_constructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A(const A&); +}; + +int main() +{ + test_has_not_nothrow_copy_constructor<void>(); + test_has_not_nothrow_copy_constructor<A>(); + + test_is_nothrow_copy_constructible<int&>(); + test_is_nothrow_copy_constructible<Union>(); + test_is_nothrow_copy_constructible<Empty>(); + test_is_nothrow_copy_constructible<int>(); + test_is_nothrow_copy_constructible<double>(); + test_is_nothrow_copy_constructible<int*>(); + test_is_nothrow_copy_constructible<const int*>(); + test_is_nothrow_copy_constructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_default_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_default_constructible.pass.cpp new file mode 100644 index 0000000000000..1550dff08bb5b --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_default_constructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_nothrow_default_constructible + +#include <type_traits> + +template <class T> +void test_is_nothrow_default_constructible() +{ + static_assert( std::is_nothrow_default_constructible<T>::value, ""); + static_assert( std::is_nothrow_default_constructible<const T>::value, ""); + static_assert( std::is_nothrow_default_constructible<volatile T>::value, ""); + static_assert( std::is_nothrow_default_constructible<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_default_constructor() +{ + static_assert(!std::is_nothrow_default_constructible<T>::value, ""); + static_assert(!std::is_nothrow_default_constructible<const T>::value, ""); + static_assert(!std::is_nothrow_default_constructible<volatile T>::value, ""); + static_assert(!std::is_nothrow_default_constructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A(); +}; + +int main() +{ + test_has_not_nothrow_default_constructor<void>(); + test_has_not_nothrow_default_constructor<int&>(); + test_has_not_nothrow_default_constructor<A>(); + + test_is_nothrow_default_constructible<Union>(); + test_is_nothrow_default_constructible<Empty>(); + test_is_nothrow_default_constructible<int>(); + test_is_nothrow_default_constructible<double>(); + test_is_nothrow_default_constructible<int*>(); + test_is_nothrow_default_constructible<const int*>(); + test_is_nothrow_default_constructible<char[3]>(); + test_is_nothrow_default_constructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp new file mode 100644 index 0000000000000..8fd5bab5a019d --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_nothrow_destructible + +#include <type_traits> + +template <class T> +void test_is_nothrow_destructible() +{ + static_assert( std::is_nothrow_destructible<T>::value, ""); + static_assert( std::is_nothrow_destructible<const T>::value, ""); + static_assert( std::is_nothrow_destructible<volatile T>::value, ""); + static_assert( std::is_nothrow_destructible<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_nothrow_destructible() +{ + static_assert(!std::is_nothrow_destructible<T>::value, ""); + static_assert(!std::is_nothrow_destructible<const T>::value, ""); + static_assert(!std::is_nothrow_destructible<volatile T>::value, ""); + static_assert(!std::is_nothrow_destructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual void foo() = 0; +}; + +class AbstractDestructor +{ + virtual ~AbstractDestructor() = 0; +}; + +struct A +{ + ~A(); +}; + +int main() +{ + test_is_not_nothrow_destructible<void>(); + test_is_not_nothrow_destructible<AbstractDestructor>(); + test_is_not_nothrow_destructible<NotEmpty>(); + test_is_not_nothrow_destructible<char[]>(); + +#if __has_feature(cxx_noexcept) + test_is_nothrow_destructible<A>(); +#endif + test_is_nothrow_destructible<int&>(); +#if __has_feature(cxx_unrestricted_unions) + test_is_nothrow_destructible<Union>(); +#endif +#if __has_feature(cxx_access_control_sfinae) + test_is_nothrow_destructible<Empty>(); +#endif + test_is_nothrow_destructible<int>(); + test_is_nothrow_destructible<double>(); + test_is_nothrow_destructible<int*>(); + test_is_nothrow_destructible<const int*>(); + test_is_nothrow_destructible<char[3]>(); + test_is_nothrow_destructible<Abstract>(); +#if __has_feature(cxx_noexcept) + test_is_nothrow_destructible<bit_zero>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_assignable.pass.cpp new file mode 100644 index 0000000000000..fe51e438864f2 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_assignable.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_nothrow_move_assign + +#include <type_traits> + +template <class T> +void test_has_nothrow_assign() +{ + static_assert( std::is_nothrow_move_assignable<T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_assign() +{ + static_assert(!std::is_nothrow_move_assignable<T>::value, ""); +} + +class Empty +{ +}; + +struct NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_nothrow_assign<int&>(); + test_has_nothrow_assign<Union>(); + test_has_nothrow_assign<Empty>(); + test_has_nothrow_assign<int>(); + test_has_nothrow_assign<double>(); + test_has_nothrow_assign<int*>(); + test_has_nothrow_assign<const int*>(); + test_has_nothrow_assign<NotEmpty>(); + test_has_nothrow_assign<bit_zero>(); + + test_has_not_nothrow_assign<void>(); + test_has_not_nothrow_assign<A>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_constructible.pass.cpp new file mode 100644 index 0000000000000..f5a42afe0d50f --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_move_constructible.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// has_nothrow_move_constructor + +#include <type_traits> + +template <class T> +void test_is_nothrow_move_constructible() +{ + static_assert( std::is_nothrow_move_constructible<T>::value, ""); + static_assert( std::is_nothrow_move_constructible<const T>::value, ""); +} + +template <class T> +void test_has_not_nothrow_move_constructor() +{ + static_assert(!std::is_nothrow_move_constructible<T>::value, ""); + static_assert(!std::is_nothrow_move_constructible<const T>::value, ""); + static_assert(!std::is_nothrow_move_constructible<volatile T>::value, ""); + static_assert(!std::is_nothrow_move_constructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +struct A +{ + A(const A&); +}; + +int main() +{ + test_has_not_nothrow_move_constructor<void>(); + test_has_not_nothrow_move_constructor<A>(); + + test_is_nothrow_move_constructible<int&>(); + test_is_nothrow_move_constructible<Union>(); + test_is_nothrow_move_constructible<Empty>(); + test_is_nothrow_move_constructible<int>(); + test_is_nothrow_move_constructible<double>(); + test_is_nothrow_move_constructible<int*>(); + test_is_nothrow_move_constructible<const int*>(); + test_is_nothrow_move_constructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp new file mode 100644 index 0000000000000..4ec1ae9949efb --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_pod.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_pod + +#include <type_traits> + +template <class T> +void test_is_pod() +{ + static_assert( std::is_pod<T>::value, ""); + static_assert( std::is_pod<const T>::value, ""); + static_assert( std::is_pod<volatile T>::value, ""); + static_assert( std::is_pod<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_pod() +{ + static_assert(!std::is_pod<T>::value, ""); + static_assert(!std::is_pod<const T>::value, ""); + static_assert(!std::is_pod<volatile T>::value, ""); + static_assert(!std::is_pod<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_pod<void>(); + test_is_not_pod<int&>(); + test_is_not_pod<Class>(); + + test_is_pod<int>(); + test_is_pod<double>(); + test_is_pod<int*>(); + test_is_pod<const int*>(); + test_is_pod<char[3]>(); + test_is_pod<char[]>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp new file mode 100644 index 0000000000000..6e82cddc51668 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_polymorphic + +#include <type_traits> + +template <class T> +void test_is_polymorphic() +{ + static_assert( std::is_polymorphic<T>::value, ""); + static_assert( std::is_polymorphic<const T>::value, ""); + static_assert( std::is_polymorphic<volatile T>::value, ""); + static_assert( std::is_polymorphic<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_polymorphic() +{ + static_assert(!std::is_polymorphic<T>::value, ""); + static_assert(!std::is_polymorphic<const T>::value, ""); + static_assert(!std::is_polymorphic<volatile T>::value, ""); + static_assert(!std::is_polymorphic<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +#if __has_feature(cxx_attributes) +class Final final { +}; +#else +class Final { +}; +#endif + +int main() +{ + test_is_not_polymorphic<void>(); + test_is_not_polymorphic<int&>(); + test_is_not_polymorphic<int>(); + test_is_not_polymorphic<double>(); + test_is_not_polymorphic<int*>(); + test_is_not_polymorphic<const int*>(); + test_is_not_polymorphic<char[3]>(); + test_is_not_polymorphic<char[]>(); + test_is_not_polymorphic<Union>(); + test_is_not_polymorphic<Empty>(); + test_is_not_polymorphic<bit_zero>(); + test_is_not_polymorphic<Final>(); + test_is_not_polymorphic<NotEmpty&>(); + test_is_not_polymorphic<Abstract&>(); + + test_is_polymorphic<NotEmpty>(); + test_is_polymorphic<Abstract>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp new file mode 100644 index 0000000000000..479c2529f02a5 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_signed + +#include <type_traits> + +template <class T> +void test_is_signed() +{ + static_assert( std::is_signed<T>::value, ""); + static_assert( std::is_signed<const T>::value, ""); + static_assert( std::is_signed<volatile T>::value, ""); + static_assert( std::is_signed<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_signed() +{ + static_assert(!std::is_signed<T>::value, ""); + static_assert(!std::is_signed<const T>::value, ""); + static_assert(!std::is_signed<volatile T>::value, ""); + static_assert(!std::is_signed<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_signed<void>(); + test_is_not_signed<int&>(); + test_is_not_signed<Class>(); + test_is_not_signed<int*>(); + test_is_not_signed<const int*>(); + test_is_not_signed<char[3]>(); + test_is_not_signed<char[]>(); + test_is_not_signed<bool>(); + test_is_not_signed<unsigned>(); + + test_is_signed<int>(); + test_is_signed<double>(); + +#ifndef _LIBCPP_HAS_NO_INT128 + test_is_signed<__int128_t>(); + test_is_not_signed<__uint128_t>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp new file mode 100644 index 0000000000000..668c4cdc7dd62 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_standard_layout.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_standard_layout + +#include <type_traits> + +template <class T> +void test_is_standard_layout() +{ + static_assert( std::is_standard_layout<T>::value, ""); + static_assert( std::is_standard_layout<const T>::value, ""); + static_assert( std::is_standard_layout<volatile T>::value, ""); + static_assert( std::is_standard_layout<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_standard_layout() +{ + static_assert(!std::is_standard_layout<T>::value, ""); + static_assert(!std::is_standard_layout<const T>::value, ""); + static_assert(!std::is_standard_layout<volatile T>::value, ""); + static_assert(!std::is_standard_layout<const volatile T>::value, ""); +} + +template <class T1, class T2> +struct pair +{ + T1 first; + T2 second; +}; + +int main() +{ + test_is_standard_layout<int> (); + test_is_standard_layout<int[3]> (); + test_is_standard_layout<pair<int, double> > (); + + test_is_not_standard_layout<int&> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp new file mode 100644 index 0000000000000..af38699d881bf --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivial.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivial + +#include <type_traits> + +template <class T> +void test_is_trivial() +{ + static_assert( std::is_trivial<T>::value, ""); + static_assert( std::is_trivial<const T>::value, ""); + static_assert( std::is_trivial<volatile T>::value, ""); + static_assert( std::is_trivial<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_trivial() +{ + static_assert(!std::is_trivial<T>::value, ""); + static_assert(!std::is_trivial<const T>::value, ""); + static_assert(!std::is_trivial<volatile T>::value, ""); + static_assert(!std::is_trivial<const volatile T>::value, ""); +} + +struct A {}; + +class B +{ +public: + B(); +}; + +int main() +{ + test_is_trivial<int> (); + test_is_trivial<A> (); + + test_is_not_trivial<int&> (); + test_is_not_trivial<volatile int&> (); + test_is_not_trivial<B> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp new file mode 100644 index 0000000000000..735d05fa6ee4b --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_assignable + +#include <type_traits> + +template <class T, class U> +void test_is_trivially_assignable() +{ + static_assert(( std::is_trivially_assignable<T, U>::value), ""); +} + +template <class T, class U> +void test_is_not_trivially_assignable() +{ + static_assert((!std::is_trivially_assignable<T, U>::value), ""); +} + +struct A +{ +}; + +struct B +{ + void operator=(A); +}; + +struct C +{ + void operator=(C&); // not const +}; + +int main() +{ + test_is_trivially_assignable<int&, int&> (); + test_is_trivially_assignable<int&, int> (); + test_is_trivially_assignable<int&, double> (); + + test_is_not_trivially_assignable<int, int&> (); + test_is_not_trivially_assignable<int, int> (); + test_is_not_trivially_assignable<B, A> (); + test_is_not_trivially_assignable<A, B> (); + test_is_not_trivially_assignable<C&, C&> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_constructible.pass.cpp new file mode 100644 index 0000000000000..4171d4d32f5d5 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_constructible.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// template <class T, class... Args> +// struct is_trivially_constructible; + +#include <type_traits> + +template <class T> +void test_is_trivially_constructible() +{ + static_assert(( std::is_trivially_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_trivially_constructible() +{ + static_assert(( std::is_trivially_constructible<T, A0>::value), ""); +} + +template <class T> +void test_is_not_trivially_constructible() +{ + static_assert((!std::is_trivially_constructible<T>::value), ""); +} + +template <class T, class A0> +void test_is_not_trivially_constructible() +{ + static_assert((!std::is_trivially_constructible<T, A0>::value), ""); +} + +template <class T, class A0, class A1> +void test_is_not_trivially_constructible() +{ + static_assert((!std::is_trivially_constructible<T, A0, A1>::value), ""); +} + +struct A +{ + explicit A(int); + A(int, double); +}; + +int main() +{ + test_is_trivially_constructible<int> (); + test_is_trivially_constructible<int, const int&> (); + + test_is_not_trivially_constructible<A, int> (); + test_is_not_trivially_constructible<A, int, double> (); + test_is_not_trivially_constructible<A> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_assignable.pass.cpp new file mode 100644 index 0000000000000..7d72565e40ca1 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_copy_assignable + +#include <type_traits> + +template <class T> +void test_has_trivially_copy_assignable() +{ + static_assert( std::is_trivially_copy_assignable<T>::value, ""); +} + +template <class T> +void test_has_not_trivially_copy_assignable() +{ + static_assert(!std::is_trivially_copy_assignable<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_trivially_copy_assignable<int&>(); + test_has_trivially_copy_assignable<Union>(); + test_has_trivially_copy_assignable<Empty>(); + test_has_trivially_copy_assignable<int>(); + test_has_trivially_copy_assignable<double>(); + test_has_trivially_copy_assignable<int*>(); + test_has_trivially_copy_assignable<const int*>(); + test_has_trivially_copy_assignable<bit_zero>(); + + test_has_not_trivially_copy_assignable<void>(); + test_has_not_trivially_copy_assignable<A>(); + test_has_not_trivially_copy_assignable<NotEmpty>(); + test_has_not_trivially_copy_assignable<Abstract>(); + test_has_not_trivially_copy_assignable<const Empty>(); + +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp new file mode 100644 index 0000000000000..6bd78ec9e7a1e --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_copy_constructible + +#include <type_traits> + +template <class T> +void test_is_trivially_copy_constructible() +{ + static_assert( std::is_trivially_copy_constructible<T>::value, ""); + static_assert( std::is_trivially_copy_constructible<const T>::value, ""); +} + +template <class T> +void test_has_not_trivial_copy_constructor() +{ + static_assert(!std::is_trivially_copy_constructible<T>::value, ""); + static_assert(!std::is_trivially_copy_constructible<const T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ +public: + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +int main() +{ + test_has_not_trivial_copy_constructor<void>(); + test_has_not_trivial_copy_constructor<A>(); + test_has_not_trivial_copy_constructor<Abstract>(); + test_has_not_trivial_copy_constructor<NotEmpty>(); + + test_is_trivially_copy_constructible<int&>(); + test_is_trivially_copy_constructible<Union>(); + test_is_trivially_copy_constructible<Empty>(); + test_is_trivially_copy_constructible<int>(); + test_is_trivially_copy_constructible<double>(); + test_is_trivially_copy_constructible<int*>(); + test_is_trivially_copy_constructible<const int*>(); + test_is_trivially_copy_constructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp new file mode 100644 index 0000000000000..d65882378fc40 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copyable.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_copyable + +#include <type_traits> +#include <cassert> + +template <class T> +void test_is_trivially_copyable() +{ + static_assert( std::is_trivially_copyable<T>::value, ""); + static_assert( std::is_trivially_copyable<const T>::value, ""); + static_assert(!std::is_trivially_copyable<volatile T>::value, ""); + static_assert(!std::is_trivially_copyable<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_trivially_copyable() +{ + static_assert(!std::is_trivially_copyable<T>::value, ""); + static_assert(!std::is_trivially_copyable<const T>::value, ""); + static_assert(!std::is_trivially_copyable<volatile T>::value, ""); + static_assert(!std::is_trivially_copyable<const volatile T>::value, ""); +} + +struct A +{ + int i_; +}; + +struct B +{ + int i_; + ~B() {assert(i_ == 0);} +}; + +class C +{ +public: + C(); +}; + +int main() +{ + test_is_trivially_copyable<int> (); + test_is_trivially_copyable<const int> (); + test_is_trivially_copyable<A> (); + test_is_trivially_copyable<const A> (); + test_is_trivially_copyable<C> (); + + test_is_not_trivially_copyable<int&> (); + test_is_not_trivially_copyable<const A&> (); + test_is_not_trivially_copyable<B> (); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_default_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_default_constructible.pass.cpp new file mode 100644 index 0000000000000..1f63401dacb75 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_default_constructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_default_constructible + +#include <type_traits> + +template <class T> +void test_is_trivially_default_constructible() +{ + static_assert( std::is_trivially_default_constructible<T>::value, ""); + static_assert( std::is_trivially_default_constructible<const T>::value, ""); + static_assert( std::is_trivially_default_constructible<volatile T>::value, ""); + static_assert( std::is_trivially_default_constructible<const volatile T>::value, ""); +} + +template <class T> +void test_has_not_trivial_default_constructor() +{ + static_assert(!std::is_trivially_default_constructible<T>::value, ""); + static_assert(!std::is_trivially_default_constructible<const T>::value, ""); + static_assert(!std::is_trivially_default_constructible<volatile T>::value, ""); + static_assert(!std::is_trivially_default_constructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A(); +}; + +int main() +{ + test_has_not_trivial_default_constructor<void>(); + test_has_not_trivial_default_constructor<int&>(); + test_has_not_trivial_default_constructor<A>(); + test_has_not_trivial_default_constructor<Abstract>(); + test_has_not_trivial_default_constructor<NotEmpty>(); + + test_is_trivially_default_constructible<Union>(); + test_is_trivially_default_constructible<Empty>(); + test_is_trivially_default_constructible<int>(); + test_is_trivially_default_constructible<double>(); + test_is_trivially_default_constructible<int*>(); + test_is_trivially_default_constructible<const int*>(); + test_is_trivially_default_constructible<char[3]>(); + test_is_trivially_default_constructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp new file mode 100644 index 0000000000000..b18ace44bda19 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_destructible + +#include <type_traits> + +template <class T> +void test_is_trivially_destructible() +{ + static_assert( std::is_trivially_destructible<T>::value, ""); + static_assert( std::is_trivially_destructible<const T>::value, ""); + static_assert( std::is_trivially_destructible<volatile T>::value, ""); + static_assert( std::is_trivially_destructible<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_trivially_destructible() +{ + static_assert(!std::is_trivially_destructible<T>::value, ""); + static_assert(!std::is_trivially_destructible<const T>::value, ""); + static_assert(!std::is_trivially_destructible<volatile T>::value, ""); + static_assert(!std::is_trivially_destructible<const volatile T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual void foo() = 0; +}; + +class AbstractDestructor +{ + virtual ~AbstractDestructor() = 0; +}; + +struct A +{ + ~A(); +}; + +int main() +{ + test_is_not_trivially_destructible<void>(); + test_is_not_trivially_destructible<A>(); + test_is_not_trivially_destructible<AbstractDestructor>(); + test_is_not_trivially_destructible<NotEmpty>(); + test_is_not_trivially_destructible<char[]>(); + + test_is_trivially_destructible<Abstract>(); + test_is_trivially_destructible<int&>(); + test_is_trivially_destructible<Union>(); + test_is_trivially_destructible<Empty>(); + test_is_trivially_destructible<int>(); + test_is_trivially_destructible<double>(); + test_is_trivially_destructible<int*>(); + test_is_trivially_destructible<const int*>(); + test_is_trivially_destructible<char[3]>(); + test_is_trivially_destructible<bit_zero>(); +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_assignable.pass.cpp new file mode 100644 index 0000000000000..c3fc7ac0a3df9 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_assignable.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_move_assignable + +#include <type_traits> + +template <class T> +void test_has_trivial_assign() +{ + static_assert( std::is_trivially_move_assignable<T>::value, ""); +} + +template <class T> +void test_has_not_trivial_assign() +{ + static_assert(!std::is_trivially_move_assignable<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ + virtual ~Abstract() = 0; +}; + +struct A +{ + A& operator=(const A&); +}; + +int main() +{ + test_has_trivial_assign<int&>(); + test_has_trivial_assign<Union>(); + test_has_trivial_assign<Empty>(); + test_has_trivial_assign<int>(); + test_has_trivial_assign<double>(); + test_has_trivial_assign<int*>(); + test_has_trivial_assign<const int*>(); + test_has_trivial_assign<bit_zero>(); + + test_has_not_trivial_assign<void>(); + test_has_not_trivial_assign<A>(); + test_has_not_trivial_assign<NotEmpty>(); + test_has_not_trivial_assign<Abstract>(); + test_has_not_trivial_assign<const Empty>(); + +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp new file mode 100644 index 0000000000000..54cb5e853a810 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_trivially_move_constructible + +#include <type_traits> + +template <class T> +void test_is_trivially_move_constructible() +{ + static_assert( std::is_trivially_move_constructible<T>::value, ""); +} + +template <class T> +void test_has_not_trivial_move_constructor() +{ + static_assert(!std::is_trivially_move_constructible<T>::value, ""); +} + +class Empty +{ +}; + +class NotEmpty +{ +public: + virtual ~NotEmpty(); +}; + +union Union {}; + +struct bit_zero +{ + int : 0; +}; + +class Abstract +{ +public: + virtual ~Abstract() = 0; +}; + +struct A +{ + A(const A&); +}; + +#if __has_feature(cxx_defaulted_functions) + +struct MoveOnly1 +{ + MoveOnly1(MoveOnly1&&); +}; + +struct MoveOnly2 +{ + MoveOnly2(MoveOnly2&&) = default; +}; + +#endif + +int main() +{ + test_has_not_trivial_move_constructor<void>(); + test_has_not_trivial_move_constructor<A>(); + test_has_not_trivial_move_constructor<Abstract>(); + test_has_not_trivial_move_constructor<NotEmpty>(); + + test_is_trivially_move_constructible<Union>(); + test_is_trivially_move_constructible<Empty>(); + test_is_trivially_move_constructible<int>(); + test_is_trivially_move_constructible<double>(); + test_is_trivially_move_constructible<int*>(); + test_is_trivially_move_constructible<const int*>(); + test_is_trivially_move_constructible<bit_zero>(); + +#if __has_feature(cxx_defaulted_functions) + static_assert(!std::is_trivially_move_constructible<MoveOnly1>::value, ""); + static_assert( std::is_trivially_move_constructible<MoveOnly2>::value, ""); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp new file mode 100644 index 0000000000000..dfdb155426101 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_unsigned + +#include <type_traits> + +template <class T> +void test_is_unsigned() +{ + static_assert( std::is_unsigned<T>::value, ""); + static_assert( std::is_unsigned<const T>::value, ""); + static_assert( std::is_unsigned<volatile T>::value, ""); + static_assert( std::is_unsigned<const volatile T>::value, ""); +} + +template <class T> +void test_is_not_unsigned() +{ + static_assert(!std::is_unsigned<T>::value, ""); + static_assert(!std::is_unsigned<const T>::value, ""); + static_assert(!std::is_unsigned<volatile T>::value, ""); + static_assert(!std::is_unsigned<const volatile T>::value, ""); +} + +class Class +{ +public: + ~Class(); +}; + +int main() +{ + test_is_not_unsigned<void>(); + test_is_not_unsigned<int&>(); + test_is_not_unsigned<Class>(); + test_is_not_unsigned<int*>(); + test_is_not_unsigned<const int*>(); + test_is_not_unsigned<char[3]>(); + test_is_not_unsigned<char[]>(); + test_is_not_unsigned<int>(); + test_is_not_unsigned<double>(); + + test_is_unsigned<bool>(); + test_is_unsigned<unsigned>(); + +#ifndef _LIBCPP_HAS_NO_INT128 + test_is_unsigned<__uint128_t>(); + test_is_not_unsigned<__int128_t>(); +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp new file mode 100644 index 0000000000000..f6805bc1c4ff6 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_volatile.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// type_traits + +// is_volatile + +#include <type_traits> + +template <class T> +void test_is_volatile() +{ + static_assert(!std::is_volatile<T>::value, ""); + static_assert(!std::is_volatile<const T>::value, ""); + static_assert( std::is_volatile<volatile T>::value, ""); + static_assert( std::is_volatile<const volatile T>::value, ""); +} + +int main() +{ + test_is_volatile<void>(); + test_is_volatile<int>(); + test_is_volatile<double>(); + test_is_volatile<int*>(); + test_is_volatile<const int*>(); + test_is_volatile<char[3]>(); + test_is_volatile<char[]>(); + + static_assert(!std::is_volatile<int&>::value, ""); + static_assert(!std::is_volatile<volatile int&>::value, ""); +} diff --git a/test/std/utilities/meta/meta.unary/nothing_to_do.pass.cpp b/test/std/utilities/meta/meta.unary/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/meta/meta.unary/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/meta/version.pass.cpp b/test/std/utilities/meta/version.pass.cpp new file mode 100644 index 0000000000000..3a1033bbb5605 --- /dev/null +++ b/test/std/utilities/meta/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <type_traits> + +#include <type_traits> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/nothing_to_do.pass.cpp b/test/std/utilities/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp new file mode 100644 index 0000000000000..e4ced3213293d --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_add.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio_add + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp new file mode 100644 index 0000000000000..a537f0215ca80 --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_add.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_add + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 2 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 127970191639601LL && R::den == 5177331081415LL, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<0> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1> R1; + typedef std::ratio<0> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<1> R2; + typedef std::ratio_add<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp new file mode 100644 index 0000000000000..bdbcda36fabc9 --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio_divide + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 2> R2; + typedef std::ratio_divide<R1, R2>::type R; +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp new file mode 100644 index 0000000000000..49b55e7a6ca8a --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_divide.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_divide + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_divide<R1, R2>::type R; + static_assert(R::num == 630992477165LL && R::den == 127339199162436LL, ""); + } +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp new file mode 100644 index 0000000000000..81acc14be14c6 --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio_multiply + +#include <ratio> + +int main() +{ + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<2, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp new file mode 100644 index 0000000000000..ccf15e07aed5b --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_multiply.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_multiply + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_multiply<R1, R2>::type R; + static_assert(R::num == 15519594064236LL && R::den == 5177331081415LL, ""); + } +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp new file mode 100644 index 0000000000000..b88314388333b --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio_subtract + +#include <ratio> + +int main() +{ + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; +} diff --git a/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp b/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp new file mode 100644 index 0000000000000..33efd90f5555b --- /dev/null +++ b/test/std/utilities/ratio/ratio.arithmetic/ratio_subtract.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_subtract + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 2, ""); + } + { + typedef std::ratio<-1, 2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -3 && R::den == 2, ""); + } + { + typedef std::ratio<1, -2> R1; + typedef std::ratio<1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -3 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<-1, 1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<1, 2> R1; + typedef std::ratio<1, -1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 3 && R::den == 2, ""); + } + { + typedef std::ratio<56987354, 467584654> R1; + typedef std::ratio<544668, 22145> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -126708206685271LL && R::den == 5177331081415LL, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<0> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 0 && R::den == 1, ""); + } + { + typedef std::ratio<1> R1; + typedef std::ratio<0> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == 1 && R::den == 1, ""); + } + { + typedef std::ratio<0> R1; + typedef std::ratio<1> R2; + typedef std::ratio_subtract<R1, R2>::type R; + static_assert(R::num == -1 && R::den == 1, ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp new file mode 100644 index 0000000000000..78027f7e48b83 --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_equal<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp new file mode 100644 index 0000000000000..9182a9ec503ca --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_greater.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_greater + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp new file mode 100644 index 0000000000000..a1f5a185e6211 --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_greater_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_greater_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_greater_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_greater_equal<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_less.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_less.pass.cpp new file mode 100644 index 0000000000000..db53ab0ad448b --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_less.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_less + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFDLL, 0x7FFFFFFFFFFFFFFCLL> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFELL> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFELL, 0x7FFFFFFFFFFFFFFDLL> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<641981, 1339063> R1; + typedef std::ratio<1291640, 2694141LL> R2; + static_assert((!std::ratio_less<R1, R2>::value), ""); + } + { + typedef std::ratio<1291640, 2694141LL> R1; + typedef std::ratio<641981, 1339063> R2; + static_assert((std::ratio_less<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp new file mode 100644 index 0000000000000..5b148f0e14359 --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_less_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_less_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_less_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_less_equal<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp b/test/std/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp new file mode 100644 index 0000000000000..ebf9307465857 --- /dev/null +++ b/test/std/utilities/ratio/ratio.comparison/ratio_not_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio_not_equal + +#include <ratio> + +int main() +{ + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((!std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 1> R1; + typedef std::ratio<1, -1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<-0x7FFFFFFFFFFFFFFFLL, 1> R1; + typedef std::ratio<0x7FFFFFFFFFFFFFFFLL, 1> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } + { + typedef std::ratio<1, 0x7FFFFFFFFFFFFFFFLL> R1; + typedef std::ratio<1, -0x7FFFFFFFFFFFFFFFLL> R2; + static_assert((std::ratio_not_equal<R1, R2>::value), ""); + } +} diff --git a/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp b/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp new file mode 100644 index 0000000000000..a7326162f40a6 --- /dev/null +++ b/test/std/utilities/ratio/ratio.ratio/ratio.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio: The static data members num and den shall have the common +// divisor of the absolute values of N and D: + +#include <ratio> + +template <long long N, long long D, long long eN, long long eD> +void test() +{ + static_assert((std::ratio<N, D>::num == eN), ""); + static_assert((std::ratio<N, D>::den == eD), ""); +} + +int main() +{ + test<1, 1, 1, 1>(); + test<1, 10, 1, 10>(); + test<10, 10, 1, 1>(); + test<10, 1, 10, 1>(); + test<12, 4, 3, 1>(); + test<12, -4, -3, 1>(); + test<-12, 4, -3, 1>(); + test<-12, -4, 3, 1>(); + test<4, 12, 1, 3>(); + test<4, -12, -1, 3>(); + test<-4, 12, -1, 3>(); + test<-4, -12, 1, 3>(); + test<222, 333, 2, 3>(); + test<222, -333, -2, 3>(); + test<-222, 333, -2, 3>(); + test<-222, -333, 2, 3>(); + test<0x7FFFFFFFFFFFFFFFLL, 127, 72624976668147841LL, 1>(); + test<-0x7FFFFFFFFFFFFFFFLL, 127, -72624976668147841LL, 1>(); + test<0x7FFFFFFFFFFFFFFFLL, -127, -72624976668147841LL, 1>(); + test<-0x7FFFFFFFFFFFFFFFLL, -127, 72624976668147841LL, 1>(); +} diff --git a/test/std/utilities/ratio/ratio.ratio/ratio1.fail.cpp b/test/std/utilities/ratio/ratio.ratio/ratio1.fail.cpp new file mode 100644 index 0000000000000..e6dbf710b71a7 --- /dev/null +++ b/test/std/utilities/ratio/ratio.ratio/ratio1.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio: The template argument D shall not be zero + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<1, 0>::num; +} diff --git a/test/std/utilities/ratio/ratio.ratio/ratio2.fail.cpp b/test/std/utilities/ratio/ratio.ratio/ratio2.fail.cpp new file mode 100644 index 0000000000000..753e79af6d0d7 --- /dev/null +++ b/test/std/utilities/ratio/ratio.ratio/ratio2.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio: the absolute values of the template arguments N and D +// shall be representable by type intmax_t. + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<0x8000000000000000ULL, 1>::num; +} diff --git a/test/std/utilities/ratio/ratio.ratio/ratio3.fail.cpp b/test/std/utilities/ratio/ratio.ratio/ratio3.fail.cpp new file mode 100644 index 0000000000000..f4b4ab9500166 --- /dev/null +++ b/test/std/utilities/ratio/ratio.ratio/ratio3.fail.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// 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 ratio: the absolute values of the template arguments N and D +// shall be representable by type intmax_t. + +#include <ratio> +#include <cstdint> + +int main() +{ + const std::intmax_t t1 = std::ratio<1, 0x8000000000000000ULL>::num; +} diff --git a/test/std/utilities/ratio/ratio.si/nothing_to_do.pass.cpp b/test/std/utilities/ratio/ratio.si/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/ratio/ratio.si/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/ratio/typedefs.pass.cpp b/test/std/utilities/ratio/typedefs.pass.cpp new file mode 100644 index 0000000000000..5ab4c740ddb63 --- /dev/null +++ b/test/std/utilities/ratio/typedefs.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test ratio typedef's + +#include <ratio> + +int main() +{ + static_assert(std::atto::num == 1 && std::atto::den == 1000000000000000000ULL, ""); + static_assert(std::femto::num == 1 && std::femto::den == 1000000000000000ULL, ""); + static_assert(std::pico::num == 1 && std::pico::den == 1000000000000ULL, ""); + static_assert(std::nano::num == 1 && std::nano::den == 1000000000ULL, ""); + static_assert(std::micro::num == 1 && std::micro::den == 1000000ULL, ""); + static_assert(std::milli::num == 1 && std::milli::den == 1000ULL, ""); + static_assert(std::centi::num == 1 && std::centi::den == 100ULL, ""); + static_assert(std::deci::num == 1 && std::deci::den == 10ULL, ""); + static_assert(std::deca::num == 10ULL && std::deca::den == 1, ""); + static_assert(std::hecto::num == 100ULL && std::hecto::den == 1, ""); + static_assert(std::kilo::num == 1000ULL && std::kilo::den == 1, ""); + static_assert(std::mega::num == 1000000ULL && std::mega::den == 1, ""); + static_assert(std::giga::num == 1000000000ULL && std::giga::den == 1, ""); + static_assert(std::tera::num == 1000000000000ULL && std::tera::den == 1, ""); + static_assert(std::peta::num == 1000000000000000ULL && std::peta::den == 1, ""); + static_assert(std::exa::num == 1000000000000000000ULL && std::exa::den == 1, ""); +} diff --git a/test/std/utilities/ratio/version.pass.cpp b/test/std/utilities/ratio/version.pass.cpp new file mode 100644 index 0000000000000..26c455fb0a9ab --- /dev/null +++ b/test/std/utilities/ratio/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <ratio> + +#include <ratio> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp b/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp new file mode 100644 index 0000000000000..7fe78bad1cc68 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// template <class charT> +// explicit bitset(const charT* str, +// typename basic_string<charT>::size_type n = basic_string<charT>::npos, +// charT zero = charT('0'), charT one = charT('1')); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_char_pointer_ctor() +{ + { + try + { + std::bitset<N> v("xxx1010101010xxxx"); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + const char str[] ="1010101010"; + std::bitset<N> v(str); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[M - 1 - i] == '1')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_char_pointer_ctor<0>(); + test_char_pointer_ctor<1>(); + test_char_pointer_ctor<31>(); + test_char_pointer_ctor<32>(); + test_char_pointer_ctor<33>(); + test_char_pointer_ctor<63>(); + test_char_pointer_ctor<64>(); + test_char_pointer_ctor<65>(); + test_char_pointer_ctor<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.cons/default.pass.cpp b/test/std/utilities/template.bitset/bitset.cons/default.pass.cpp new file mode 100644 index 0000000000000..bd5ca7e08b2ab --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.cons/default.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test default ctor + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_default_ctor() +{ + { + _LIBCPP_CONSTEXPR std::bitset<N> v1; + assert(v1.size() == N); + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == false); + } +} + +int main() +{ + test_default_ctor<0>(); + test_default_ctor<1>(); + test_default_ctor<31>(); + test_default_ctor<32>(); + test_default_ctor<33>(); + test_default_ctor<63>(); + test_default_ctor<64>(); + test_default_ctor<65>(); + test_default_ctor<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp b/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp new file mode 100644 index 0000000000000..bcee50c4c63ac --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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 bitset(string, pos, n, zero, one); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_string_ctor() +{ + { + try + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, str.size()+1, 10); + assert(false); + } + catch (std::out_of_range&) + { + } + } + + { + try + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, 2, 10); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + std::string str("xxx1010101010xxxx"); + std::bitset<N> v(str, 3, 10); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[3 + M - 1 - i] == '1')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } + + { + try + { + std::string str("xxxbababababaxxxx"); + std::bitset<N> v(str, 2, 10, 'a', 'b'); + assert(false); + } + catch (std::invalid_argument&) + { + } + } + + { + std::string str("xxxbababababaxxxx"); + std::bitset<N> v(str, 3, 10, 'a', 'b'); + std::size_t M = std::min<std::size_t>(N, 10); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (str[3 + M - 1 - i] == 'b')); + for (std::size_t i = 10; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_string_ctor<0>(); + test_string_ctor<1>(); + test_string_ctor<31>(); + test_string_ctor<32>(); + test_string_ctor<33>(); + test_string_ctor<63>(); + test_string_ctor<64>(); + test_string_ctor<65>(); + test_string_ctor<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp b/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp new file mode 100644 index 0000000000000..023fedc258393 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 bitset(unsigned long long val); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_val_ctor() +{ + { + _LIBCPP_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL); + assert(v.size() == N); + unsigned M = std::min<std::size_t>(N, 64); + for (std::size_t i = 0; i < M; ++i) + assert(v[i] == (i & 1)); + for (std::size_t i = M; i < N; ++i) + assert(v[i] == false); + } +} + +int main() +{ + test_val_ctor<0>(); + test_val_ctor<1>(); + test_val_ctor<31>(); + test_val_ctor<32>(); + test_val_ctor<33>(); + test_val_ctor<63>(); + test_val_ctor<64>(); + test_val_ctor<65>(); + test_val_ctor<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp new file mode 100644 index 0000000000000..520f2e8757c27 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include <bitset> +#include <cassert> +#include <type_traits> + +template <std::size_t N> +void +test() +{ + typedef std::bitset<N> T; + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + H h; + T bs(static_cast<unsigned long long>(N)); + assert(h(bs) == N); +} + +int main() +{ + test<0>(); + test<10>(); + test<100>(); + test<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/all.pass.cpp new file mode 100644 index 0000000000000..5387b733918fe --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/all.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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 bool all() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_all() +{ + std::bitset<N> v; + v.reset(); + assert(v.all() == (N == 0)); + v.set(); + assert(v.all() == true); + if (N > 1) + { + v[N/2] = false; + assert(v.all() == false); + } +} + +int main() +{ + test_all<0>(); + test_all<1>(); + test_all<31>(); + test_all<32>(); + test_all<33>(); + test_all<63>(); + test_all<64>(); + test_all<65>(); + test_all<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/any.pass.cpp b/test/std/utilities/template.bitset/bitset.members/any.pass.cpp new file mode 100644 index 0000000000000..aa6384a49df1d --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/any.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bool any() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_any() +{ + std::bitset<N> v; + v.reset(); + assert(v.any() == false); + v.set(); + assert(v.any() == (N != 0)); + if (N > 1) + { + v[N/2] = false; + assert(v.any() == true); + v.reset(); + v[N/2] = true; + assert(v.any() == true); + } +} + +int main() +{ + test_any<0>(); + test_any<1>(); + test_any<31>(); + test_any<32>(); + test_any<33>(); + test_any<63>(); + test_any<64>(); + test_any<65>(); + test_any<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/count.pass.cpp b/test/std/utilities/template.bitset/bitset.members/count.pass.cpp new file mode 100644 index 0000000000000..fb9ce6422997a --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/count.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test size_t count() const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_count() +{ + const std::bitset<N> v = make_bitset<N>(); + std::size_t c1 = v.count(); + std::size_t c2 = 0; + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + ++c2; + assert(c1 == c2); +} + +int main() +{ + test_count<0>(); + test_count<1>(); + test_count<31>(); + test_count<32>(); + test_count<33>(); + test_count<63>(); + test_count<64>(); + test_count<65>(); + test_count<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp new file mode 100644 index 0000000000000..6c4f5c699850e --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/flip_all.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& flip(); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_flip_all() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v2.flip(); + for (std::size_t i = 0; i < N; ++i) + assert(v2[i] == ~v1[i]); +} + +int main() +{ + test_flip_all<0>(); + test_flip_all<1>(); + test_flip_all<31>(); + test_flip_all<32>(); + test_flip_all<33>(); + test_flip_all<63>(); + test_flip_all<64>(); + test_flip_all<65>(); + test_flip_all<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp new file mode 100644 index 0000000000000..3e09b202097d8 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& flip(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_flip_one() +{ + std::bitset<N> v = make_bitset<N>(); + try + { + v.flip(50); + bool b = v[50]; + if (50 >= v.size()) + assert(false); + assert(v[50] == b); + v.flip(50); + assert(v[50] != b); + v.flip(50); + assert(v[50] == b); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_flip_one<0>(); + test_flip_one<1>(); + test_flip_one<31>(); + test_flip_one<32>(); + test_flip_one<33>(); + test_flip_one<63>(); + test_flip_one<64>(); + test_flip_one<65>(); + test_flip_one<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/index.pass.cpp b/test/std/utilities/template.bitset/bitset.members/index.pass.cpp new file mode 100644 index 0000000000000..b96aaa51ab8fc --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/index.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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 bitset<N>::reference operator[](size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_index_const() +{ + std::bitset<N> v1 = make_bitset<N>(); + if (N > 0) + { + assert(v1[N/2] == v1.test(N/2)); + typename std::bitset<N>::reference r = v1[N/2]; + assert(r == v1.test(N/2)); + typename std::bitset<N>::reference r2 = v1[N/2]; + r = r2; + assert(r == v1.test(N/2)); + r = false; + assert(r == false); + assert(v1.test(N/2) == false); + r = true; + assert(r == true); + assert(v1.test(N/2) == true); + bool b = ~r; + assert(r == true); + assert(v1.test(N/2) == true); + assert(b == false); + r.flip(); + assert(r == false); + assert(v1.test(N/2) == false); + } +} + +int main() +{ + test_index_const<0>(); + test_index_const<1>(); + test_index_const<31>(); + test_index_const<32>(); + test_index_const<33>(); + test_index_const<63>(); + test_index_const<64>(); + test_index_const<65>(); + test_index_const<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp b/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp new file mode 100644 index 0000000000000..e3c28c6935767 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test constexpr bool operator[](size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_index_const() +{ + const std::bitset<N> v1 = make_bitset<N>(); + if (N > 0) + { + assert(v1[N/2] == v1.test(N/2)); + } +} + +int main() +{ + test_index_const<0>(); + test_index_const<1>(); + test_index_const<31>(); + test_index_const<32>(); + test_index_const<33>(); + test_index_const<63>(); + test_index_const<64>(); + test_index_const<65>(); + test_index_const<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/left_shift.pass.cpp b/test/std/utilities/template.bitset/bitset.members/left_shift.pass.cpp new file mode 100644 index 0000000000000..7fe9fa72e9243 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/left_shift.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator<<(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_left_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert((v1 <<= s) == (v2 << s)); + } +} + +int main() +{ + test_left_shift<0>(); + test_left_shift<1>(); + test_left_shift<31>(); + test_left_shift<32>(); + test_left_shift<33>(); + test_left_shift<63>(); + test_left_shift<64>(); + test_left_shift<65>(); + test_left_shift<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp new file mode 100644 index 0000000000000..bed3e28ece818 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator<<=(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_left_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v1 <<= s; + for (std::size_t i = 0; i < N; ++i) + if (i < s) + assert(v1[i] == 0); + else + assert(v1[i] == v2[i-s]); + } +} + +int main() +{ + test_left_shift<0>(); + test_left_shift<1>(); + test_left_shift<31>(); + test_left_shift<32>(); + test_left_shift<33>(); + test_left_shift<63>(); + test_left_shift<64>(); + test_left_shift<65>(); + test_left_shift<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/none.pass.cpp b/test/std/utilities/template.bitset/bitset.members/none.pass.cpp new file mode 100644 index 0000000000000..b65c636f3c560 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/none.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bool none() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_none() +{ + std::bitset<N> v; + v.reset(); + assert(v.none() == true); + v.set(); + assert(v.none() == (N == 0)); + if (N > 1) + { + v[N/2] = false; + assert(v.none() == false); + v.reset(); + v[N/2] = true; + assert(v.none() == false); + } +} + +int main() +{ + test_none<0>(); + test_none<1>(); + test_none<31>(); + test_none<32>(); + test_none<33>(); + test_none<63>(); + test_none<64>(); + test_none<65>(); + test_none<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/not_all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/not_all.pass.cpp new file mode 100644 index 0000000000000..2f8f7111f5a13 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/not_all.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator~() const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_not_all() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = ~v1; + for (std::size_t i = 0; i < N; ++i) + assert(v2[i] == ~v1[i]); +} + +int main() +{ + test_not_all<0>(); + test_not_all<1>(); + test_not_all<31>(); + test_not_all<32>(); + test_not_all<33>(); + test_not_all<63>(); + test_not_all<64>(); + test_not_all<65>(); + test_not_all<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp new file mode 100644 index 0000000000000..b599ec398b309 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator&=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_and_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 &= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] && v2[i])); +} + +int main() +{ + test_op_and_eq<0>(); + test_op_and_eq<1>(); + test_op_and_eq<31>(); + test_op_and_eq<32>(); + test_op_and_eq<33>(); + test_op_and_eq<63>(); + test_op_and_eq<64>(); + test_op_and_eq<65>(); + test_op_and_eq<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp new file mode 100644 index 0000000000000..5f6cf3d0a30c1 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test: + +// bool operator==(const bitset<N>& rhs) const; +// bool operator!=(const bitset<N>& rhs) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_equality() +{ + const std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert(v1 == v2); + if (N > 0) + { + v2[N/2].flip(); + assert(v1 != v2); + } +} + +int main() +{ + test_equality<0>(); + test_equality<1>(); + test_equality<31>(); + test_equality<32>(); + test_equality<33>(); + test_equality<63>(); + test_equality<64>(); + test_equality<65>(); + test_equality<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp new file mode 100644 index 0000000000000..6e63879890a64 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator|=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_or_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 |= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] || v2[i])); +} + +int main() +{ + test_op_or_eq<0>(); + test_op_or_eq<1>(); + test_op_or_eq<31>(); + test_op_or_eq<32>(); + test_op_or_eq<33>(); + test_op_or_eq<63>(); + test_op_or_eq<64>(); + test_op_or_eq<65>(); + test_op_or_eq<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp new file mode 100644 index 0000000000000..e68a641cadc66 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator^=(const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_xor_eq() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + v1 ^= v2; + for (std::size_t i = 0; i < N; ++i) + assert(v1[i] == (v3[i] != v2[i])); +} + +int main() +{ + test_op_xor_eq<0>(); + test_op_xor_eq<1>(); + test_op_xor_eq<31>(); + test_op_xor_eq<32>(); + test_op_xor_eq<33>(); + test_op_xor_eq<63>(); + test_op_xor_eq<64>(); + test_op_xor_eq<65>(); + test_op_xor_eq<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/reset_all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/reset_all.pass.cpp new file mode 100644 index 0000000000000..ee44d92c43b8e --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/reset_all.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 bitset<N>& reset(); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_reset_all() +{ + std::bitset<N> v; + v.set(); + v.reset(); + for (std::size_t i = 0; i < N; ++i) + assert(!v[i]); +} + +int main() +{ + test_reset_all<0>(); + test_reset_all<1>(); + test_reset_all<31>(); + test_reset_all<32>(); + test_reset_all<33>(); + test_reset_all<63>(); + test_reset_all<64>(); + test_reset_all<65>(); + test_reset_all<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp new file mode 100644 index 0000000000000..ebaa9e7a8d722 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& reset(size_t pos); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_reset_one() +{ + std::bitset<N> v; + try + { + v.set(); + v.reset(50); + if (50 >= v.size()) + assert(false); + for (unsigned i = 0; i < v.size(); ++i) + if (i == 50) + assert(!v[i]); + else + assert(v[i]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_reset_one<0>(); + test_reset_one<1>(); + test_reset_one<31>(); + test_reset_one<32>(); + test_reset_one<33>(); + test_reset_one<63>(); + test_reset_one<64>(); + test_reset_one<65>(); + test_reset_one<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/right_shift.pass.cpp b/test/std/utilities/template.bitset/bitset.members/right_shift.pass.cpp new file mode 100644 index 0000000000000..87fcc281fa26e --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/right_shift.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator>>(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_right_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + assert((v1 >>= s) == (v2 >> s)); + } +} + +int main() +{ + test_right_shift<0>(); + test_right_shift<1>(); + test_right_shift<31>(); + test_right_shift<32>(); + test_right_shift<33>(); + test_right_shift<63>(); + test_right_shift<64>(); + test_right_shift<65>(); + test_right_shift<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp new file mode 100644 index 0000000000000..1dd89c1844b94 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/right_shift_eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& operator<<=(size_t pos); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_right_shift() +{ + for (std::size_t s = 0; s <= N+1; ++s) + { + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = v1; + v1 >>= s; + for (std::size_t i = 0; i < N; ++i) + if (i + s < N) + assert(v1[i] == v2[i + s]); + else + assert(v1[i] == 0); + } +} + +int main() +{ + test_right_shift<0>(); + test_right_shift<1>(); + test_right_shift<31>(); + test_right_shift<32>(); + test_right_shift<33>(); + test_right_shift<63>(); + test_right_shift<64>(); + test_right_shift<65>(); + test_right_shift<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/set_all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/set_all.pass.cpp new file mode 100644 index 0000000000000..56454a84f1135 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/set_all.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 bitset<N>& set(); + +#include <bitset> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +void test_set_all() +{ + std::bitset<N> v; + v.set(); + for (std::size_t i = 0; i < N; ++i) + assert(v[i]); +} + +int main() +{ + test_set_all<0>(); + test_set_all<1>(); + test_set_all<31>(); + test_set_all<32>(); + test_set_all<33>(); + test_set_all<63>(); + test_set_all<64>(); + test_set_all<65>(); + test_set_all<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp new file mode 100644 index 0000000000000..116eaf3f46e02 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N>& set(size_t pos, bool val = true); + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_set_one() +{ + std::bitset<N> v; + try + { + v.set(50); + if (50 >= v.size()) + assert(false); + assert(v[50]); + } + catch (std::out_of_range&) + { + } + try + { + v.set(50, false); + if (50 >= v.size()) + assert(false); + assert(!v[50]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_set_one<0>(); + test_set_one<1>(); + test_set_one<31>(); + test_set_one<32>(); + test_set_one<33>(); + test_set_one<63>(); + test_set_one<64>(); + test_set_one<65>(); + test_set_one<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/size.pass.cpp b/test/std/utilities/template.bitset/bitset.members/size.pass.cpp new file mode 100644 index 0000000000000..822e0a048b5ab --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/size.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 size_t count() const; + +#include <bitset> +#include <cassert> + +template <std::size_t N> +void test_size() +{ + const std::bitset<N> v; + assert(v.size() == N); +} + +int main() +{ + test_size<0>(); + test_size<1>(); + test_size<31>(); + test_size<32>(); + test_size<33>(); + test_size<63>(); + test_size<64>(); + test_size<65>(); + test_size<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/test.pass.cpp b/test/std/utilities/template.bitset/bitset.members/test.pass.cpp new file mode 100644 index 0000000000000..5102b46171a28 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/test.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test constexpr bool test(size_t pos) const; + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_test() +{ + const std::bitset<N> v1 = make_bitset<N>(); + try + { + bool b = v1.test(50); + if (50 >= v1.size()) + assert(false); + assert(b == v1[50]); + } + catch (std::out_of_range&) + { + } +} + +int main() +{ + test_test<0>(); + test_test<1>(); + test_test<31>(); + test_test<32>(); + test_test<33>(); + test_test<63>(); + test_test<64>(); + test_test<65>(); + test_test<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/to_string.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_string.pass.cpp new file mode 100644 index 0000000000000..b65794097470f --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/to_string.pass.cpp @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// 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: + +// template <class charT, class traits, class Allocator> +// basic_string<charT, traits, Allocator> +// to_string(charT zero = charT('0'), charT one = charT('1')) const; +// +// template <class charT, class traits> +// basic_string<charT, traits, allocator<charT> > to_string() const; +// +// template <class charT> +// basic_string<charT, char_traits<charT>, allocator<charT> > to_string() const; +// +// basic_string<char, char_traits<char>, allocator<char> > to_string() const; + +#include <bitset> +#include <string> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_to_string() +{ +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string(); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string('0'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +{ + std::bitset<N> v = make_bitset<N>(); + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::wstring s = v.template to_string<wchar_t, std::char_traits<wchar_t> >('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.template to_string<char>('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } + { + std::string s = v.to_string('0', '1'); + for (std::size_t i = 0; i < N; ++i) + if (v[i]) + assert(s[N - 1 - i] == '1'); + else + assert(s[N - 1 - i] == '0'); + } +} +} + +int main() +{ + test_to_string<0>(); + test_to_string<1>(); + test_to_string<31>(); + test_to_string<32>(); + test_to_string<33>(); + test_to_string<63>(); + test_to_string<64>(); + test_to_string<65>(); + test_to_string<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp new file mode 100644 index 0000000000000..27d8480d10cfe --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test unsigned long long to_ullong() const; + +#include <bitset> +#include <algorithm> +#include <climits> +#include <cassert> + +template <std::size_t N> +void test_to_ullong() +{ + const std::size_t M = sizeof(unsigned long long) * CHAR_BIT < N ? sizeof(unsigned long long) * CHAR_BIT : N; + const std::size_t X = M == 0 ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M; + const unsigned long long max = M == 0 ? 0 : (unsigned long long)(-1) >> X; + unsigned long long tests[] = {0, + std::min<unsigned long long>(1, max), + std::min<unsigned long long>(2, max), + std::min<unsigned long long>(3, max), + std::min(max, max-3), + std::min(max, max-2), + std::min(max, max-1), + max}; + for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) + { + unsigned long long j = tests[i]; + std::bitset<N> v(j); + assert(j == v.to_ullong()); + } +} + +int main() +{ + test_to_ullong<0>(); + test_to_ullong<1>(); + test_to_ullong<31>(); + test_to_ullong<32>(); + test_to_ullong<33>(); + test_to_ullong<63>(); + test_to_ullong<64>(); + test_to_ullong<65>(); + test_to_ullong<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp new file mode 100644 index 0000000000000..3ad1abade9f48 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test unsigned long to_ulong() const; + +#include <bitset> +#include <algorithm> +#include <limits> +#include <climits> +#include <cassert> + +template <std::size_t N> +void test_to_ulong() +{ + const std::size_t M = sizeof(unsigned long) * CHAR_BIT < N ? sizeof(unsigned long) * CHAR_BIT : N; + const std::size_t X = M == 0 ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M; + const std::size_t max = M == 0 ? 0 : std::size_t(std::numeric_limits<unsigned long>::max()) >> X; + std::size_t tests[] = {0, + std::min<std::size_t>(1, max), + std::min<std::size_t>(2, max), + std::min<std::size_t>(3, max), + std::min(max, max-3), + std::min(max, max-2), + std::min(max, max-1), + max}; + for (std::size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) + { + std::size_t j = tests[i]; + std::bitset<N> v(j); + assert(j == v.to_ulong()); + } +} + +int main() +{ + test_to_ulong<0>(); + test_to_ulong<1>(); + test_to_ulong<31>(); + test_to_ulong<32>(); + test_to_ulong<33>(); + test_to_ulong<63>(); + test_to_ulong<64>(); + test_to_ulong<65>(); + test_to_ulong<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp b/test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp new file mode 100644 index 0000000000000..751cee69102a3 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.operators/op_and.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_and() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 & v2) == (v3 &= v2));; +} + +int main() +{ + test_op_and<0>(); + test_op_and<1>(); + test_op_and<31>(); + test_op_and<32>(); + test_op_and<33>(); + test_op_and<63>(); + test_op_and<64>(); + test_op_and<65>(); + test_op_and<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp b/test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp new file mode 100644 index 0000000000000..fda5e5cda8eea --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.operators/op_not.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_not() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 ^ v2) == (v3 ^= v2));; +} + +int main() +{ + test_op_not<0>(); + test_op_not<1>(); + test_op_not<31>(); + test_op_not<32>(); + test_op_not<33>(); + test_op_not<63>(); + test_op_not<64>(); + test_op_not<65>(); + test_op_not<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp b/test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp new file mode 100644 index 0000000000000..067f868215be9 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.operators/op_or.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs); + +#include <bitset> +#include <cstdlib> +#include <cassert> + +#pragma clang diagnostic ignored "-Wtautological-compare" + +template <std::size_t N> +std::bitset<N> +make_bitset() +{ + std::bitset<N> v; + for (std::size_t i = 0; i < N; ++i) + v[i] = static_cast<bool>(std::rand() & 1); + return v; +} + +template <std::size_t N> +void test_op_or() +{ + std::bitset<N> v1 = make_bitset<N>(); + std::bitset<N> v2 = make_bitset<N>(); + std::bitset<N> v3 = v1; + assert((v1 | v2) == (v3 |= v2));; +} + +int main() +{ + test_op_or<0>(); + test_op_or<1>(); + test_op_or<31>(); + test_op_or<32>(); + test_op_or<33>(); + test_op_or<63>(); + test_op_or<64>(); + test_op_or<65>(); + test_op_or<1000>(); +} diff --git a/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp b/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp new file mode 100644 index 0000000000000..4c8afe3f96b0f --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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: + +// template <class charT, class traits, size_t N> +// basic_ostream<charT, traits>& +// operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); + +#include <bitset> +#include <sstream> +#include <cassert> + +int main() +{ + std::istringstream in("01011010"); + std::bitset<8> b; + in >> b; + assert(b.to_ulong() == 0x5A); +} diff --git a/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp b/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp new file mode 100644 index 0000000000000..05efe27fae85f --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.operators/stream_out.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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: + +// template <class charT, class traits, size_t N> +// basic_istream<charT, traits>& +// operator>>(basic_istream<charT, traits>& is, bitset<N>& x); + +#include <bitset> +#include <sstream> +#include <cassert> + +int main() +{ + std::ostringstream os; + std::bitset<8> b(0x5A); + os << b; + assert(os.str() == "01011010"); +} diff --git a/test/std/utilities/template.bitset/includes.pass.cpp b/test/std/utilities/template.bitset/includes.pass.cpp new file mode 100644 index 0000000000000..2e3c2812e441a --- /dev/null +++ b/test/std/utilities/template.bitset/includes.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test that <bitset> includes <cstddef>, <string>, <stdexcept> and <iosfwd> + +#include <bitset> + +#ifndef _LIBCPP_CSTDDEF +#error <cstddef> has not been included +#endif + +#ifndef _LIBCPP_STRING +#error <string> has not been included +#endif + +#ifndef _LIBCPP_STDEXCEPT +#error <stdexcept> has not been included +#endif + +#ifndef _LIBCPP_IOSFWD +#error <iosfwd> has not been included +#endif + +int main() +{ +} diff --git a/test/std/utilities/template.bitset/version.pass.cpp b/test/std/utilities/template.bitset/version.pass.cpp new file mode 100644 index 0000000000000..5ae984c0092df --- /dev/null +++ b/test/std/utilities/template.bitset/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <bitset> + +#include <bitset> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/time/clock.h b/test/std/utilities/time/clock.h new file mode 100644 index 0000000000000..c72470c9cc8d3 --- /dev/null +++ b/test/std/utilities/time/clock.h @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef CLOCK_H +#define CLOCK_H + +#include <chrono> + +class Clock +{ + typedef std::chrono::nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef std::chrono::time_point<Clock, duration> time_point; + static const bool is_steady = false; + + static time_point now(); +}; + +#endif // CLOCK_H diff --git a/test/std/utilities/time/hours.pass.cpp b/test/std/utilities/time/hours.pass.cpp new file mode 100644 index 0000000000000..e4c39f7859e70 --- /dev/null +++ b/test/std/utilities/time/hours.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 23 bits, ratio<3600>> hours; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::hours D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 22, ""); + static_assert((std::is_same<Period, std::ratio<3600> >::value), ""); +} diff --git a/test/std/utilities/time/microseconds.pass.cpp b/test/std/utilities/time/microseconds.pass.cpp new file mode 100644 index 0000000000000..1fe6b10da5acb --- /dev/null +++ b/test/std/utilities/time/microseconds.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 55 bits, micro> microseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::microseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 54, ""); + static_assert((std::is_same<Period, std::micro>::value), ""); +} diff --git a/test/std/utilities/time/milliseconds.pass.cpp b/test/std/utilities/time/milliseconds.pass.cpp new file mode 100644 index 0000000000000..75df301f7a65a --- /dev/null +++ b/test/std/utilities/time/milliseconds.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 45 bits, milli> milliseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::milliseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 44, ""); + static_assert((std::is_same<Period, std::milli>::value), ""); +} diff --git a/test/std/utilities/time/minutes.pass.cpp b/test/std/utilities/time/minutes.pass.cpp new file mode 100644 index 0000000000000..14214861c073f --- /dev/null +++ b/test/std/utilities/time/minutes.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 29 bits, ratio< 60>> minutes; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::minutes D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 28, ""); + static_assert((std::is_same<Period, std::ratio<60> >::value), ""); +} diff --git a/test/std/utilities/time/nanoseconds.pass.cpp b/test/std/utilities/time/nanoseconds.pass.cpp new file mode 100644 index 0000000000000..d422803f45231 --- /dev/null +++ b/test/std/utilities/time/nanoseconds.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 64 bits, nano> nanoseconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::nanoseconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 63, ""); + static_assert((std::is_same<Period, std::nano>::value), ""); +} diff --git a/test/std/utilities/time/rep.h b/test/std/utilities/time/rep.h new file mode 100644 index 0000000000000..2ec3514ab567a --- /dev/null +++ b/test/std/utilities/time/rep.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef REP_H +#define REP_H + +class Rep +{ + int data_; +public: + _LIBCPP_CONSTEXPR Rep() : data_(-1) {} + explicit _LIBCPP_CONSTEXPR Rep(int i) : data_(i) {} + + bool _LIBCPP_CONSTEXPR operator==(int i) const {return data_ == i;} + bool _LIBCPP_CONSTEXPR operator==(const Rep& r) const {return data_ == r.data_;} + + Rep& operator*=(Rep x) {data_ *= x.data_; return *this;} + Rep& operator/=(Rep x) {data_ /= x.data_; return *this;} +}; + +#endif // REP_H diff --git a/test/std/utilities/time/seconds.pass.cpp b/test/std/utilities/time/seconds.pass.cpp new file mode 100644 index 0000000000000..231d59695a0ad --- /dev/null +++ b/test/std/utilities/time/seconds.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// typedef duration<signed integral type of at least 35 bits > seconds; + +#include <chrono> +#include <type_traits> +#include <limits> + +int main() +{ + typedef std::chrono::seconds D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed<Rep>::value, ""); + static_assert(std::is_integral<Rep>::value, ""); + static_assert(std::numeric_limits<Rep>::digits >= 34, ""); + static_assert((std::is_same<Period, std::ratio<1> >::value), ""); +} diff --git a/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp b/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/time/time.clock.req/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp b/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/time/time.clock/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp new file mode 100644 index 0000000000000..2e3acbc52b115 --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <chrono> + +// high_resolution_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::high_resolution_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_steady || !C::is_steady, ""); + test(std::chrono::high_resolution_clock::is_steady); +} diff --git a/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp b/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp new file mode 100644 index 0000000000000..ab67cd838f935 --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.hires/now.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// high_resolution_clock + +// static time_point now(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::high_resolution_clock C; + C::time_point t1 = C::now(); + assert(t1.time_since_epoch().count() != 0); + assert(C::time_point::min() < t1); + assert(C::time_point::max() > t1); +} diff --git a/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp new file mode 100644 index 0000000000000..0e0b83b2f2440 --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// UNSUPPORTED: libcpp-has-no-monotonic-clock + +// <chrono> + +// steady_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::steady_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert(C::is_steady, ""); + test(std::chrono::steady_clock::is_steady); +} diff --git a/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp b/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp new file mode 100644 index 0000000000000..4b86d9e8cbc4e --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-monotonic-clock + +// <chrono> + +// steady_clock + +// static time_point now(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::steady_clock C; + C::time_point t1 = C::now(); + C::time_point t2 = C::now(); + assert(t2 >= t1); +} diff --git a/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp new file mode 100644 index 0000000000000..e277d4e67dc7a --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// This test uses new symbols that were not defined in the libc++ shipped on +// darwin11 and darwin12: +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 +// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 + +// <chrono> + +// system_clock + +// check clock invariants + +#include <chrono> + +template <class _Tp> +void test(const _Tp &) {} + +int main() +{ + typedef std::chrono::system_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert((std::is_same<C::time_point::clock, C>::value), ""); + static_assert((C::is_steady || !C::is_steady), ""); + test(std::chrono::system_clock::is_steady); +} diff --git a/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp new file mode 100644 index 0000000000000..f4a454f57801f --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.system/from_time_t.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point from_time_t(time_t t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::from_time_t(C::to_time_t(C::now())); + ((void)t1); +} diff --git a/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp new file mode 100644 index 0000000000000..ebc0db80b6484 --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.system/now.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// static time_point now(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock C; + C::time_point t1 = C::now(); + assert(t1.time_since_epoch().count() != 0); + assert(C::time_point::min() < t1); + assert(C::time_point::max() > t1); +} diff --git a/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp new file mode 100644 index 0000000000000..b6a440e16dd4b --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.system/rep_signed.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// rep should be signed + +#include <chrono> +#include <cassert> + +int main() +{ + assert(std::chrono::system_clock::duration::min() < + std::chrono::system_clock::duration::zero()); +} diff --git a/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp new file mode 100644 index 0000000000000..c4028063bc536 --- /dev/null +++ b/test/std/utilities/time/time.clock/time.clock.system/to_time_t.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// system_clock + +// time_t to_time_t(const time_point& t); + +#include <chrono> +#include <ctime> + +int main() +{ + typedef std::chrono::system_clock C; + std::time_t t1 = C::to_time_t(C::now()); + ((void)t1); +} diff --git a/test/std/utilities/time/time.duration/default_ratio.pass.cpp b/test/std/utilities/time/time.duration/default_ratio.pass.cpp new file mode 100644 index 0000000000000..a34e27832bdc4 --- /dev/null +++ b/test/std/utilities/time/time.duration/default_ratio.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Test default template arg: + +// template <class Rep, class Period = ratio<1>> +// class duration; + +#include <chrono> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::chrono::duration<int, std::ratio<1> >, + std::chrono::duration<int> >::value), ""); +} diff --git a/test/std/utilities/time/time.duration/duration.fail.cpp b/test/std/utilities/time/time.duration/duration.fail.cpp new file mode 100644 index 0000000000000..053616b79b437 --- /dev/null +++ b/test/std/utilities/time/time.duration/duration.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// If a program instantiates duration with a duration type for the template +// argument Rep a diagnostic is required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<std::chrono::milliseconds> D; + D d; +} diff --git a/test/std/utilities/time/time.duration/positive_num.fail.cpp b/test/std/utilities/time/time.duration/positive_num.fail.cpp new file mode 100644 index 0000000000000..e9096fd3fcb7a --- /dev/null +++ b/test/std/utilities/time/time.duration/positive_num.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period::num shall be positive, diagnostic required. + +#include <chrono> + +int main() +{ + typedef std::chrono::duration<int, std::ratio<5, -1> > D; + D d; +} diff --git a/test/std/utilities/time/time.duration/ratio.fail.cpp b/test/std/utilities/time/time.duration/ratio.fail.cpp new file mode 100644 index 0000000000000..4ce0aaad003e6 --- /dev/null +++ b/test/std/utilities/time/time.duration/ratio.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Period shall be a specialization of ratio, diagnostic required. + +#include <chrono> + +template <int N, int D = 1> +class Ratio +{ +public: + static const int num = N; + static const int den = D; +}; + +int main() +{ + typedef std::chrono::duration<int, Ratio<1> > D; + D d; +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp new file mode 100644 index 0000000000000..8a8f4b1c0d9b0 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator++(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = ++h; + assert(&href == &h); + assert(h.count() == 4); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp new file mode 100644 index 0000000000000..cf5028281007d --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator++(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h++; + assert(h.count() == 4); + assert(h2.count() == 3); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp new file mode 100644 index 0000000000000..c0f10147ee893 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator+() const; + +#include <chrono> +#include <cassert> + +int main() +{ + { + const std::chrono::minutes m(3); + std::chrono::minutes m2 = +m; + assert(m.count() == m2.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = +m; + static_assert(m.count() == m2.count(), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp new file mode 100644 index 0000000000000..8d8cf4539c16b --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator+=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s += std::chrono::seconds(2); + assert(s.count() == 5); + s += std::chrono::minutes(2); + assert(s.count() == 125); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp new file mode 100644 index 0000000000000..0aadfbcd5991e --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator--(); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours& href = --h; + assert(&href == &h); + assert(h.count() == 2); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp new file mode 100644 index 0000000000000..7fc6a1df603f4 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_--int.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator--(int); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::hours h(3); + std::chrono::hours h2 = h--; + assert(h.count() == 2); + assert(h2.count() == 3); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp new file mode 100644 index 0000000000000..00da6f69ca530 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration operator-() const; + +#include <chrono> +#include <cassert> + +int main() +{ + { + const std::chrono::minutes m(3); + std::chrono::minutes m2 = -m; + assert(m2.count() == -m.count()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::minutes m(3); + constexpr std::chrono::minutes m2 = -m; + static_assert(m2.count() == -m.count(), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp new file mode 100644 index 0000000000000..a0a7aed202b1b --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-=.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator-=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::seconds s(3); + s -= std::chrono::seconds(2); + assert(s.count() == 1); + s -= std::chrono::minutes(2); + assert(s.count() == -119); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp new file mode 100644 index 0000000000000..09786bcd8cf84 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_divide=.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator/=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(15); + ns /= 5; + assert(ns.count() == 3); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp new file mode 100644 index 0000000000000..8a4a2b4723244 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=duration.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const duration& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + std::chrono::microseconds us2(3); + us %= us2; + assert(us.count() == 2); + us %= std::chrono::milliseconds(3); + assert(us.count() == 2); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp new file mode 100644 index 0000000000000..8758e17ba6afd --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_mod=rep.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator%=(const rep& rhs) + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::microseconds us(11); + us %= 3; + assert(us.count() == 2); +} diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp new file mode 100644 index 0000000000000..b97534a3615a9 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_times=.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration& operator*=(const rep& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::nanoseconds ns(3); + ns *= 5; + assert(ns.count() == 15); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp new file mode 100644 index 0000000000000..1c87fcd909efc --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/duration_cast.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// duration_cast(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::duration_cast<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::duration_cast<ToDuration>(f) == d); + } +} + +int main() +{ + test(std::chrono::milliseconds(7265000), std::chrono::hours(2)); + test(std::chrono::milliseconds(7265000), std::chrono::minutes(121)); + test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265)); + test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000)); + test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL)); + test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL)); + test(std::chrono::milliseconds(7265000), + std::chrono::duration<double, std::ratio<3600> >(7265./3600)); + test(std::chrono::duration<int, std::ratio<2, 3> >(9), + std::chrono::duration<int, std::ratio<3, 5> >(10)); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::hours h = std::chrono::duration_cast<std::chrono::hours>(std::chrono::milliseconds(7265000)); + static_assert(h.count() == 2, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp new file mode 100644 index 0000000000000..13dd8f44c364e --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/toduration.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class ToDuration, class Rep, class Period> +// ToDuration +// duration_cast(const duration<Rep, Period>& d); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + std::chrono::duration_cast<int>(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp b/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp new file mode 100644 index 0000000000000..2d0dd94d4cf65 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.comparisons/op_equal.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 == s2)); + assert(s1 != s2); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(s1 == s2); + assert(!(s1 != s2)); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9); + static_assert(!(s1 == s2), ""); + static_assert(s1 != s2, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10); + static_assert(s1 == s2, ""); + static_assert(!(s1 != s2), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp b/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp new file mode 100644 index 0000000000000..9d875579f3262 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.comparisons/op_less.pass.cpp @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// bool +// operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(3); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(4); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(3000); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::milliseconds s1(3); + std::chrono::microseconds s2(4000); + assert( (s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert(!(s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<int, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(10); + std::chrono::duration<int, std::ratio<3, 5> > s2(9); + assert(!(s1 < s2)); + assert( (s1 > s2)); + assert(!(s1 <= s2)); + assert( (s1 >= s2)); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(9); + std::chrono::duration<double, std::ratio<3, 5> > s2(10); + assert(!(s1 < s2)); + assert(!(s1 > s2)); + assert( (s1 <= s2)); + assert( (s1 >= s2)); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(3); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(4); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(3000); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::milliseconds s1(3); + constexpr std::chrono::microseconds s2(4000); + static_assert( (s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert(!(s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9); + static_assert(!(s1 < s2), ""); + static_assert( (s1 > s2), ""); + static_assert(!(s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10); + static_assert(!(s1 < s2), ""); + static_assert(!(s1 > s2), ""); + static_assert( (s1 <= s2), ""); + static_assert( (s1 >= s2), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp new file mode 100644 index 0000000000000..152227d82a823 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_exact.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// exact conversions allowed for integral reps + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::milliseconds ms(1); + std::chrono::microseconds us = ms; + assert(us.count() == 1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::milliseconds ms(1); + constexpr std::chrono::microseconds us = ms; + static_assert(us.count() == 1000, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp new file mode 100644 index 0000000000000..04c082578289f --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_float_to_int.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from floating point to integral durations disallowed + +#include <chrono> + +int main() +{ + std::chrono::duration<double> d; + std::chrono::duration<int> i = d; +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp new file mode 100644 index 0000000000000..e82e25e8f694c --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions disallowed for integral reps + +#include <chrono> + +int main() +{ + std::chrono::microseconds us(1); + std::chrono::milliseconds ms = us; +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp new file mode 100644 index 0000000000000..519b2b141c298 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_inexact.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// inexact conversions allowed for floating point reps + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::duration<double, std::micro> us(1); + std::chrono::duration<double, std::milli> ms = us; + assert(ms.count() == 1./1000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration<double, std::micro> us(1); + constexpr std::chrono::duration<double, std::milli> ms = us; + static_assert(ms.count() == 1./1000, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp new file mode 100644 index 0000000000000..59fefe2e002d5 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_int_to_float.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// conversions from integral to floating point durations allowed + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::duration<int> i(3); + std::chrono::duration<double, std::milli> d = i; + assert(d.count() == 3000); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::duration<int> i(3); + constexpr std::chrono::duration<double, std::milli> d = i; + static_assert(d.count() == 3000, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp new file mode 100644 index 0000000000000..74b65d6b9cc7e --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/convert_overflow.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2, class Period2> +// duration(const duration<Rep2, Period2>& d); + +// overflow should SFINAE instead of error out, LWG 2094 + +#include <chrono> +#include <cassert> + +bool called = false; + +void f(std::chrono::milliseconds); +void f(std::chrono::seconds) +{ + called = true; +} + +int main() +{ + { + std::chrono::duration<int, std::exa> r(1); + f(r); + assert(called); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp new file mode 100644 index 0000000000000..c52990961c259 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/default.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// duration() = default; + +// Rep must be default initialized, not initialized with 0 + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void +test() +{ + D d; + assert(d.count() == typename D::rep()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2 = D(); + static_assert(d2.count() == typename D::rep(), ""); +#endif +} + +int main() +{ + test<std::chrono::duration<Rep> >(); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp new file mode 100644 index 0000000000000..20f81619bd125 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/rep.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D, class R> +void +test(R r) +{ + D d(r); + assert(d.count() == r); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr D d2(R(2)); + static_assert(d2.count() == 2, ""); +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(5); + test<std::chrono::duration<int, std::ratio<3, 2> > >(5); + test<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3)); + test<std::chrono::duration<double, std::ratio<2, 3> > >(5.5); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp new file mode 100644 index 0000000000000..9f071ca1afc0f --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/rep01.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// test for explicit + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<int> d = 1; +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp new file mode 100644 index 0000000000000..37f32e77686a1 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/rep02.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// Rep2 shall be implicitly convertible to rep + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(1); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp new file mode 100644 index 0000000000000..b3ba9f7081e45 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/rep02.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// construct double with int + +#include <chrono> +#include <cassert> + +int main() +{ + std::chrono::duration<double> d(5); + assert(d.count() == 5); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + constexpr std::chrono::duration<double> d2(5); + static_assert(d2.count() == 5, ""); +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp new file mode 100644 index 0000000000000..4ace54b231ffe --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cons/rep03.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep2> +// explicit duration(const Rep2& r); + +// treat_as_floating_point<Rep2>::value shall be false + +#include <chrono> + +int main() +{ + std::chrono::duration<int> d(1.); +} diff --git a/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp b/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp new file mode 100644 index 0000000000000..48324ae836513 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals::chrono_literals; + +// Make sure the types are right + static_assert ( std::is_same<decltype( 3h ), std::chrono::hours>::value, "" ); + static_assert ( std::is_same<decltype( 3min ), std::chrono::minutes>::value, "" ); + static_assert ( std::is_same<decltype( 3s ), std::chrono::seconds>::value, "" ); + static_assert ( std::is_same<decltype( 3ms ), std::chrono::milliseconds>::value, "" ); + static_assert ( std::is_same<decltype( 3us ), std::chrono::microseconds>::value, "" ); + static_assert ( std::is_same<decltype( 3ns ), std::chrono::nanoseconds>::value, "" ); + + std::chrono::hours h = 4h; + assert ( h == std::chrono::hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + std::chrono::minutes min = 36min; + assert ( min == std::chrono::minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + std::chrono::seconds s = 24s; + assert ( s == std::chrono::seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + std::chrono::milliseconds ms = 247ms; + assert ( ms == std::chrono::milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + std::chrono::microseconds us = 867us; + assert ( us == std::chrono::microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + std::chrono::nanoseconds ns = 645ns; + assert ( ns == std::chrono::nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp b/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp new file mode 100644 index 0000000000000..46aaa30e51e4a --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.literals/literals1.fail.cpp @@ -0,0 +1,21 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::chrono::hours h = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} + diff --git a/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp b/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp new file mode 100644 index 0000000000000..574f9bcce8741 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp @@ -0,0 +1,48 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::chrono; + + hours h = 4h; + assert ( h == hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + minutes min = 36min; + assert ( min == minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + seconds s = 24s; + assert ( s == seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + milliseconds ms = 247ms; + assert ( ms == milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + microseconds us = 867us; + assert ( us == microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + nanoseconds ns = 645ns; + assert ( ns == nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp b/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp new file mode 100644 index 0000000000000..17358e589f4fa --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.literals/literals2.fail.cpp @@ -0,0 +1,22 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <chrono> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::chrono::hours; + + hours foo = 4h; // should fail w/conversion operator not found +#else +#error +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp b/test/std/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp new file mode 100644 index 0000000000000..e37bc6e679614 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.literals/literals2.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> +#include <type_traits> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using namespace std::literals; + + std::chrono::hours h = 4h; + assert ( h == std::chrono::hours(4)); + auto h2 = 4.0h; + assert ( h == h2 ); + + std::chrono::minutes min = 36min; + assert ( min == std::chrono::minutes(36)); + auto min2 = 36.0min; + assert ( min == min2 ); + + std::chrono::seconds s = 24s; + assert ( s == std::chrono::seconds(24)); + auto s2 = 24.0s; + assert ( s == s2 ); + + std::chrono::milliseconds ms = 247ms; + assert ( ms == std::chrono::milliseconds(247)); + auto ms2 = 247.0ms; + assert ( ms == ms2 ); + + std::chrono::microseconds us = 867us; + assert ( us == std::chrono::microseconds(867)); + auto us2 = 867.0us; + assert ( us == us2 ); + + std::chrono::nanoseconds ns = 645ns; + assert ( ns == std::chrono::nanoseconds(645)); + auto ns2 = 645.ns; + assert ( ns == ns2 ); +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp new file mode 100644 index 0000000000000..6585351cb4c8e --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_+.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 + s2; + assert(r.count() == 8); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 + s2; + assert(r.count() == 3000005); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2; + assert(r.count() == 75); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 + s2; + static_assert(r.count() == 8, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 + s2; + static_assert(r.count() == 3000005, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2; + static_assert(r.count() == 75, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2; + static_assert(r.count() == 75, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp new file mode 100644 index 0000000000000..fac58b9716d3b --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_-.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::seconds s1(3); + std::chrono::seconds s2(5); + std::chrono::seconds r = s1 - s2; + assert(r.count() == -2); + } + { + std::chrono::seconds s1(3); + std::chrono::microseconds s2(5); + std::chrono::microseconds r = s1 - s2; + assert(r.count() == 2999995); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(3); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; + assert(r.count() == -15); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::seconds s2(5); + constexpr std::chrono::seconds r = s1 - s2; + static_assert(r.count() == -2, ""); + } + { + constexpr std::chrono::seconds s1(3); + constexpr std::chrono::microseconds s2(5); + constexpr std::chrono::microseconds r = s1 - s2; + static_assert(r.count() == 2999995, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; + static_assert(r.count() == -15, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; + static_assert(r.count() == -15, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp new file mode 100644 index 0000000000000..6b24676f100cf --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_duration.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<Rep1, Rep2>::type +// operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(5); + assert(ns1 / ns2 == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(5); + assert(us1 / ns2 == 3000); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<int, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 6); + } + { + std::chrono::duration<int, std::ratio<2, 3> > s1(30); + std::chrono::duration<double, std::ratio<3, 5> > s2(5); + assert(s1 / s2 == 20./3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(ns1 / ns2 == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(5); + static_assert(us1 / ns2 == 3000, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(30); + constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); + static_assert(s1 / s2 == 6, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(30); + constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); + static_assert(s1 / s2 == 20./3, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp new file mode 100644 index 0000000000000..db725773fd474 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d / 5; +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp new file mode 100644 index 0000000000000..3036cde5bf677 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_divide_rep.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator/(const duration<Rep1, Period>& d, const Rep2& s); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(15); + ns = ns / 5; + assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns / 5; + static_assert(ns2.count() == 3, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp new file mode 100644 index 0000000000000..e69f3205d14ff --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period1, class Rep2, class Period2> +// constexpr +// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type +// operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns1(15); + std::chrono::nanoseconds ns2(6); + std::chrono::nanoseconds r = ns1 % ns2; + assert(r.count() == 3); + } + { + std::chrono::microseconds us1(15); + std::chrono::nanoseconds ns2(28); + std::chrono::nanoseconds r = us1 % ns2; + assert(r.count() == 20); + } + { + std::chrono::duration<int, std::ratio<3, 5> > s1(6); + std::chrono::duration<int, std::ratio<2, 3> > s2(3); + std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2; + assert(r.count() == 24); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns1(15); + constexpr std::chrono::nanoseconds ns2(6); + constexpr std::chrono::nanoseconds r = ns1 % ns2; + static_assert(r.count() == 3, ""); + } + { + constexpr std::chrono::microseconds us1(15); + constexpr std::chrono::nanoseconds ns2(28); + constexpr std::chrono::nanoseconds r = us1 % ns2; + static_assert(r.count() == 20, ""); + } + { + constexpr std::chrono::duration<int, std::ratio<3, 5> > s1(6); + constexpr std::chrono::duration<int, std::ratio<2, 3> > s2(3); + constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2; + static_assert(r.count() == 24, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp new file mode 100644 index 0000000000000..16e511d44f66f --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator%(const duration<Rep1, Period>& d, const Rep2& s) + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d(Rep(15)); + d = d % 5; +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp new file mode 100644 index 0000000000000..1acbe34ea5eb1 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_mod_rep.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator%(const duration<Rep1, Period>& d, const Rep2& s) + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(15); + ns = ns % 6; + assert(ns.count() == 3); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(15); + constexpr std::chrono::nanoseconds ns2 = ns % 6; + static_assert(ns2.count() == 3, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp new file mode 100644 index 0000000000000..190e74b1dc32a --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// constexpr +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> +#include <cassert> + +int main() +{ + { + std::chrono::nanoseconds ns(3); + ns = ns * 5; + assert(ns.count() == 15); + ns = 6 * ns; + assert(ns.count() == 90); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::chrono::nanoseconds ns(3); + constexpr std::chrono::nanoseconds ns2 = ns * 5; + static_assert(ns2.count() == 15, ""); + constexpr std::chrono::nanoseconds ns3 = 6 * ns; + static_assert(ns3.count() == 18, ""); + } +#endif +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp new file mode 100644 index 0000000000000..d8160500f916e --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep1.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d; + d = d * 5; +} diff --git a/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp new file mode 100644 index 0000000000000..e224ba9421099 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.nonmember/op_times_rep2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const duration<Rep1, Period>& d, const Rep2& s); + +// template <class Rep1, class Period, class Rep2> +// duration<typename common_type<Rep1, Rep2>::type, Period> +// operator*(const Rep1& s, const duration<Rep2, Period>& d); + +#include <chrono> + +#include "../../rep.h" + +int main() +{ + std::chrono::duration<Rep> d; + d = 5 * d; +} diff --git a/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp b/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.observer/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp b/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp new file mode 100644 index 0000000000000..405461e88ae9b --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.special/max.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration max(); + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep max_rep = std::chrono::duration_values<Rep>::max(); + assert(D::max().count() == max_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep max_rep = std::chrono::duration_values<Rep>::max(); + static_assert(D::max().count() == max_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp b/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp new file mode 100644 index 0000000000000..44cd64eff3d36 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.special/min.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration min(); + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep min_rep = std::chrono::duration_values<Rep>::min(); + assert(D::min().count() == min_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep min_rep = std::chrono::duration_values<Rep>::min(); + static_assert(D::min().count() == min_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp b/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp new file mode 100644 index 0000000000000..18350fe2ff476 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.special/zero.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// static constexpr duration zero(); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +template <class D> +void test() +{ + { + typedef typename D::rep Rep; + Rep zero_rep = std::chrono::duration_values<Rep>::zero(); + assert(D::zero().count() == zero_rep); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef typename D::rep Rep; + constexpr Rep zero_rep = std::chrono::duration_values<Rep>::zero(); + static_assert(D::zero().count() == zero_rep, ""); + } +#endif +} + +int main() +{ + test<std::chrono::duration<int> >(); + test<std::chrono::duration<Rep> >(); +} diff --git a/test/std/utilities/time/time.duration/types.pass.cpp b/test/std/utilities/time/time.duration/types.pass.cpp new file mode 100644 index 0000000000000..8eaffe77651cc --- /dev/null +++ b/test/std/utilities/time/time.duration/types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration + +// Test nested types + +// typedef Rep rep; +// typedef Period period; + +#include <chrono> +#include <type_traits> + +int main() +{ + typedef std::chrono::duration<long, std::ratio<3, 2> > D; + static_assert((std::is_same<D::rep, long>::value), ""); + static_assert((std::is_same<D::period, std::ratio<3, 2> >::value), ""); +} diff --git a/test/std/utilities/time/time.point/default_duration.pass.cpp b/test/std/utilities/time/time.point/default_duration.pass.cpp new file mode 100644 index 0000000000000..dfdf225ed4726 --- /dev/null +++ b/test/std/utilities/time/time.point/default_duration.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// Test default template arg: + +// template <class Clock, class Duration = typename Clock::duration> +// class time_point; + +#include <chrono> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::chrono::system_clock::duration, + std::chrono::time_point<std::chrono::system_clock>::duration>::value), ""); +} diff --git a/test/std/utilities/time/time.point/duration.fail.cpp b/test/std/utilities/time/time.point/duration.fail.cpp new file mode 100644 index 0000000000000..ee48bcb392eca --- /dev/null +++ b/test/std/utilities/time/time.point/duration.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// Duration shall be an instance of duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::time_point<std::chrono::system_clock, int> T; + T t; +} diff --git a/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp b/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp new file mode 100644 index 0000000000000..ffe855ce90311 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point& operator+=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t(Duration(3)); + t += Duration(2); + assert(t.time_since_epoch() == Duration(5)); +} diff --git a/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp b/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp new file mode 100644 index 0000000000000..acad1cfecb448 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point& operator-=(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t(Duration(3)); + t -= Duration(2); + assert(t.time_since_epoch() == Duration(1)); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp new file mode 100644 index 0000000000000..7d7e82ac5e239 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/time_point_cast.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// time_point_cast(const time_point<Clock, Duration>& t); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class FromDuration, class ToDuration> +void +test(const FromDuration& df, const ToDuration& d) +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + FromTimePoint f(df); + ToTimePoint t(d); + typedef decltype(std::chrono::time_point_cast<ToDuration>(f)) R; + static_assert((std::is_same<R, ToTimePoint>::value), ""); + assert(std::chrono::time_point_cast<ToDuration>(f) == t); + } +} + +#if _LIBCPP_STD_VER > 11 + +template<class FromDuration, long long From, class ToDuration, long long To> +void test_constexpr () +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; + typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; + { + constexpr FromTimePoint f{FromDuration{From}}; + constexpr ToTimePoint t{ToDuration{To}}; + static_assert(std::chrono::time_point_cast<ToDuration>(f) == t, ""); + } + +} + +#endif + +int main() +{ + test(std::chrono::milliseconds(7265000), std::chrono::hours(2)); + test(std::chrono::milliseconds(7265000), std::chrono::minutes(121)); + test(std::chrono::milliseconds(7265000), std::chrono::seconds(7265)); + test(std::chrono::milliseconds(7265000), std::chrono::milliseconds(7265000)); + test(std::chrono::milliseconds(7265000), std::chrono::microseconds(7265000000LL)); + test(std::chrono::milliseconds(7265000), std::chrono::nanoseconds(7265000000000LL)); + test(std::chrono::milliseconds(7265000), + std::chrono::duration<double, std::ratio<3600> >(7265./3600)); + test(std::chrono::duration<int, std::ratio<2, 3> >(9), + std::chrono::duration<int, std::ratio<3, 5> >(10)); +#if _LIBCPP_STD_VER > 11 + { + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::hours, 2> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::minutes,121> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::seconds,7265> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::milliseconds,7265000> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::microseconds,7265000000LL> (); + test_constexpr<std::chrono::milliseconds, 7265000, std::chrono::nanoseconds,7265000000000LL> (); + typedef std::chrono::duration<int, std::ratio<3, 5>> T1; + test_constexpr<std::chrono::duration<int, std::ratio<2, 3>>, 9, T1, 10> (); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp new file mode 100644 index 0000000000000..de1e5bb3e2739 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/toduration.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class ToDuration, class Clock, class Duration> +// time_point<Clock, ToDuration> +// time_point_cast(const time_point<Clock, Duration>& t); + +// ToDuration shall be an instantiation of duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::time_point<Clock, std::chrono::milliseconds> FromTimePoint; + typedef std::chrono::time_point<Clock, std::chrono::minutes> ToTimePoint; + std::chrono::time_point_cast<ToTimePoint>(FromTimePoint(std::chrono::milliseconds(3))); +} diff --git a/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp b/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp new file mode 100644 index 0000000000000..f5ff11958ba23 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.comparisons/op_equal.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_points with different clocks should not compare + +#include <chrono> + +#include "../../clock.h" + +int main() +{ + typedef std::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock1, Duration1> T1; + typedef std::chrono::time_point<Clock2, Duration2> T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 == t2; +} diff --git a/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp b/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp new file mode 100644 index 0000000000000..fbd3a1386d35b --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.comparisons/op_equal.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock, Duration1> T1; + typedef std::chrono::time_point<Clock, Duration2> T2; + + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + assert( (t1 == t2)); + assert(!(t1 != t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + assert(!(t1 == t2)); + assert( (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + assert( (t1 == t2)); + assert(!(t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + assert(!(t1 == t2)); + assert( (t1 != t2)); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(3)); + static_assert( (t1 == t2), ""); + static_assert(!(t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(4)); + static_assert(!(t1 == t2), ""); + static_assert( (t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3000)); + static_assert( (t1 == t2), ""); + static_assert(!(t1 != t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3001)); + static_assert(!(t1 == t2), ""); + static_assert( (t1 != t2), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp b/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp new file mode 100644 index 0000000000000..f9745cbf9de73 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.comparisons/op_less.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// time_points with different clocks should not compare + +#include <chrono> + +#include "../../clock.h" + +int main() +{ + typedef std::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock1, Duration1> T1; + typedef std::chrono::time_point<Clock2, Duration2> T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 < t2; +} diff --git a/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp b/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp new file mode 100644 index 0000000000000..9d94400ed3d17 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.comparisons/op_less.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +// template <class Clock, class Duration1, class Duration2> +// bool +// operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + typedef std::chrono::time_point<Clock, Duration1> T1; + typedef std::chrono::time_point<Clock, Duration2> T2; + + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + assert(!(t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + assert( (t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert(!(t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + assert(!(t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + assert( (t1 < t2)); + assert(!(t1 > t2)); + assert( (t1 <= t2)); + assert(!(t1 >= t2)); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(3)); + static_assert(!(t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert( (t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T1 t2(Duration1(4)); + static_assert( (t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3000)); + static_assert(!(t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert( (t1 >= t2), ""); + } + { + constexpr T1 t1(Duration1(3)); + constexpr T2 t2(Duration2(3001)); + static_assert( (t1 < t2), ""); + static_assert(!(t1 > t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 >= t2), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp b/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp new file mode 100644 index 0000000000000..565aa6c4f52f2 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cons/convert.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Duration2> +// time_point(const time_point<clock, Duration2>& t); + +// Duration2 shall be implicitly convertible to duration. + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + std::chrono::time_point<Clock, Duration1> t1 = t2; + } +} diff --git a/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp b/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp new file mode 100644 index 0000000000000..6cd7dcb7d2f4a --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cons/convert.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Duration2> +// time_point(const time_point<clock, Duration2>& t); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::microseconds Duration1; + typedef std::chrono::milliseconds Duration2; + { + std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + std::chrono::time_point<Clock, Duration1> t1 = t2; + assert(t1.time_since_epoch() == Duration1(3000)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration2> t2(Duration2(3)); + constexpr std::chrono::time_point<Clock, Duration1> t1 = t2; + static_assert(t1.time_since_epoch() == Duration1(3000), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp b/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp new file mode 100644 index 0000000000000..01f0bc1699332 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cons/default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// time_point(); + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::duration<Rep, std::milli> Duration; + { + std::chrono::time_point<Clock, Duration> t; + assert(t.time_since_epoch() == Duration::zero()); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration> t; + static_assert(t.time_since_epoch() == Duration::zero(), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp b/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp new file mode 100644 index 0000000000000..810007ed94257 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cons/duration.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// explicit time_point(const duration& d); + +// test for explicit + +#include <chrono> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + std::chrono::time_point<Clock, Duration> t = Duration(3); +} diff --git a/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp b/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp new file mode 100644 index 0000000000000..9d53d86dea3be --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cons/duration.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// explicit time_point(const duration& d); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + { + std::chrono::time_point<Clock, Duration> t(Duration(3)); + assert(t.time_since_epoch() == Duration(3)); + } + { + std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); + assert(t.time_since_epoch() == Duration(3000)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration> t(Duration(3)); + static_assert(t.time_since_epoch() == Duration(3), ""); + } + { + constexpr std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); + static_assert(t.time_since_epoch() == Duration(3000), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp b/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp new file mode 100644 index 0000000000000..7a8fa6dcf14fd --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.nonmember/op_+.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); + +// template <class Rep1, class Period1, class Clock, class Duration2> +// time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> +// operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5); + assert(t2.time_since_epoch() == Duration2(3005)); + t2 = Duration2(6) + t1; + assert(t2.time_since_epoch() == Duration2(3006)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5); + static_assert(t2.time_since_epoch() == Duration2(3005), ""); + constexpr std::chrono::time_point<Clock, Duration2> t3 = Duration2(6) + t1; + static_assert(t3.time_since_epoch() == Duration2(3006), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp b/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp new file mode 100644 index 0000000000000..342d27b5aebdc --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.nonmember/op_-duration.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Rep2, class Period2> +// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> +// operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); + assert(t2.time_since_epoch() == Duration2(2995)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); + static_assert(t2.time_since_epoch() == Duration2(2995), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp b/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp new file mode 100644 index 0000000000000..5267f07e1b86e --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.nonmember/op_-time_point.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// template <class Clock, class Duration1, class Duration2> +// typename common_type<Duration1, Duration2>::type +// operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration1; + typedef std::chrono::microseconds Duration2; + { + std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + std::chrono::time_point<Clock, Duration2> t2(Duration2(5)); + assert((t1 - t2) == Duration2(2995)); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); + constexpr std::chrono::time_point<Clock, Duration2> t2(Duration2(5)); + static_assert((t1 - t2) == Duration2(2995), ""); + } +#endif +} diff --git a/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp b/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.observer/tested_elsewhere.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/time/time.point/time.point.special/max.pass.cpp b/test/std/utilities/time/time.point/time.point.special/max.pass.cpp new file mode 100644 index 0000000000000..6bba6fc827876 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.special/max.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// static constexpr time_point max(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + typedef std::chrono::time_point<Clock, Duration> TP; + assert(TP::max() == TP(Duration::max())); +} diff --git a/test/std/utilities/time/time.point/time.point.special/min.pass.cpp b/test/std/utilities/time/time.point/time.point.special/min.pass.cpp new file mode 100644 index 0000000000000..b1d955c252aaf --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.special/min.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// time_point + +// static constexpr time_point min(); + +#include <chrono> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef std::chrono::milliseconds Duration; + typedef std::chrono::time_point<Clock, Duration> TP; + assert(TP::min() == TP(Duration::min())); +} diff --git a/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp b/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/time/time.traits/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp b/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp new file mode 100644 index 0000000000000..89dc1dcc1a594 --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.duration_values/max.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::max + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::max() == + std::numeric_limits<int>::max()); + assert(std::chrono::duration_values<double>::max() == + std::numeric_limits<double>::max()); + assert(std::chrono::duration_values<Rep>::max() == + std::numeric_limits<Rep>::max()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::max() == + std::numeric_limits<int>::max(), ""); + static_assert(std::chrono::duration_values<double>::max() == + std::numeric_limits<double>::max(), ""); + static_assert(std::chrono::duration_values<Rep>::max() == + std::numeric_limits<Rep>::max(), ""); +#endif +} diff --git a/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp b/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp new file mode 100644 index 0000000000000..69812bba006aa --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.duration_values/min.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::min + +#include <chrono> +#include <limits> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::min() == + std::numeric_limits<int>::lowest()); + assert(std::chrono::duration_values<double>::min() == + std::numeric_limits<double>::lowest()); + assert(std::chrono::duration_values<Rep>::min() == + std::numeric_limits<Rep>::lowest()); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::min() == + std::numeric_limits<int>::lowest(), ""); + static_assert(std::chrono::duration_values<double>::min() == + std::numeric_limits<double>::lowest(), ""); + static_assert(std::chrono::duration_values<Rep>::min() == + std::numeric_limits<Rep>::lowest(), ""); +#endif +} diff --git a/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp b/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp new file mode 100644 index 0000000000000..234b4bc31c9d2 --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.duration_values/zero.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// duration_values::zero + +#include <chrono> +#include <cassert> + +#include "../../rep.h" + +int main() +{ + assert(std::chrono::duration_values<int>::zero() == 0); + assert(std::chrono::duration_values<Rep>::zero() == 0); +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + static_assert(std::chrono::duration_values<int>::zero() == 0, ""); + static_assert(std::chrono::duration_values<Rep>::zero() == 0, ""); +#endif +} diff --git a/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp b/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp new file mode 100644 index 0000000000000..c32350faa83b5 --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.is_fp/treat_as_floating_point.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// treat_as_floating_point + +#include <chrono> +#include <type_traits> + +template <class T> +void +test() +{ + static_assert((std::is_base_of<std::is_floating_point<T>, + std::chrono::treat_as_floating_point<T> >::value), ""); +} + +struct A {}; + +int main() +{ + test<int>(); + test<unsigned>(); + test<char>(); + test<bool>(); + test<float>(); + test<double>(); + test<long double>(); + test<A>(); +} diff --git a/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp b/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp new file mode 100644 index 0000000000000..f942844b60a64 --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.specializations/duration.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// template <class Rep1, class Period1, class Rep2, class Period2> +// struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> +// { +// typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below }> type; +// }; + +#include <chrono> + +template <class D1, class D2, class De> +void +test() +{ + typedef typename std::common_type<D1, D2>::type Dc; + static_assert((std::is_same<Dc, De>::value), ""); +} + +int main() +{ + test<std::chrono::duration<int, std::ratio<1, 100> >, + std::chrono::duration<long, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<long, std::ratio<1, 100> >, + std::chrono::duration<int, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<char, std::ratio<1, 30> >, + std::chrono::duration<short, std::ratio<1, 1000> >, + std::chrono::duration<int, std::ratio<1, 3000> > >(); + test<std::chrono::duration<double, std::ratio<21, 1> >, + std::chrono::duration<short, std::ratio<15, 1> >, + std::chrono::duration<double, std::ratio<3, 1> > >(); +} diff --git a/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp b/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp new file mode 100644 index 0000000000000..a0786b49924c7 --- /dev/null +++ b/test/std/utilities/time/time.traits/time.traits.specializations/time_point.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +// template <class Clock, class Duration1, class Duration2> +// struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> +// { +// typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type; +// }; + +#include <chrono> + +template <class D1, class D2, class De> +void +test() +{ + typedef std::chrono::system_clock C; + typedef std::chrono::time_point<C, D1> T1; + typedef std::chrono::time_point<C, D2> T2; + typedef std::chrono::time_point<C, De> Te; + typedef typename std::common_type<T1, T2>::type Tc; + static_assert((std::is_same<Tc, Te>::value), ""); +} + +int main() +{ + test<std::chrono::duration<int, std::ratio<1, 100> >, + std::chrono::duration<long, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<long, std::ratio<1, 100> >, + std::chrono::duration<int, std::ratio<1, 1000> >, + std::chrono::duration<long, std::ratio<1, 1000> > >(); + test<std::chrono::duration<char, std::ratio<1, 30> >, + std::chrono::duration<short, std::ratio<1, 1000> >, + std::chrono::duration<int, std::ratio<1, 3000> > >(); + test<std::chrono::duration<double, std::ratio<21, 1> >, + std::chrono::duration<short, std::ratio<15, 1> >, + std::chrono::duration<double, std::ratio<3, 1> > >(); +} diff --git a/test/std/utilities/time/version.pass.cpp b/test/std/utilities/time/version.pass.cpp new file mode 100644 index 0000000000000..bfa3f6d6797d9 --- /dev/null +++ b/test/std/utilities/time/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <chrono> + +#include <chrono> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/tuple/tuple.general/tuple.smartptr.pass.cpp b/test/std/utilities/tuple/tuple.general/tuple.smartptr.pass.cpp new file mode 100644 index 0000000000000..1d8be420d8376 --- /dev/null +++ b/test/std/utilities/tuple/tuple.general/tuple.smartptr.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// Tuples of smart pointers; based on bug #18350 +// auto_ptr doesn't have a copy constructor that takes a const &, but tuple does. + +#include <tuple> +#include <memory> + +int main () { + { + std::tuple<std::unique_ptr<char>> up; + std::tuple<std::shared_ptr<char>> sp; + std::tuple<std::weak_ptr <char>> wp; +// std::tuple<std::auto_ptr <char>> ap; + } + { + std::tuple<std::unique_ptr<char[]>> up; + std::tuple<std::shared_ptr<char[]>> sp; + std::tuple<std::weak_ptr <char[]>> wp; +// std::tuple<std::auto_ptr <char[]>> ap; + } + { + std::tuple<std::unique_ptr<char[5]>> up; + std::tuple<std::shared_ptr<char[5]>> sp; + std::tuple<std::weak_ptr <char[5]>> wp; +// std::tuple<std::auto_ptr <char[5]>> ap; + } +}
\ No newline at end of file diff --git a/test/std/utilities/tuple/tuple.tuple/TupleFunction.pass.cpp b/test/std/utilities/tuple/tuple.tuple/TupleFunction.pass.cpp new file mode 100644 index 0000000000000..df5fdff511e35 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/TupleFunction.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// This is for bugs 18853 and 19118 + +#if __cplusplus >= 201103L + +#include <tuple> +#include <functional> + +struct X +{ + X() {} + + template <class T> + X(T); + + void operator()() {} +}; + +int +main() +{ + X x; + std::function<void()> f(x); +} +#else +int main () {} +#endif diff --git a/test/std/utilities/tuple/tuple.tuple/alloc_first.h b/test/std/utilities/tuple/tuple.tuple/alloc_first.h new file mode 100644 index 0000000000000..237a2897e87ae --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/alloc_first.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef ALLOC_FIRST_H +#define ALLOC_FIRST_H + +#include <cassert> + +#include "allocators.h" + +struct alloc_first +{ + static bool allocator_constructed; + + typedef A1<int> allocator_type; + + int data_; + + alloc_first() : data_(0) {} + alloc_first(int d) : data_(d) {} + alloc_first(std::allocator_arg_t, const A1<int>& a) + : data_(0) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_first(std::allocator_arg_t, const A1<int>& a, int d) + : data_(d) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_first(std::allocator_arg_t, const A1<int>& a, const alloc_first& d) + : data_(d.data_) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + ~alloc_first() {data_ = -1;} + + friend bool operator==(const alloc_first& x, const alloc_first& y) + {return x.data_ == y.data_;} + friend bool operator< (const alloc_first& x, const alloc_first& y) + {return x.data_ < y.data_;} +}; + +bool alloc_first::allocator_constructed = false; + +#endif // ALLOC_FIRST_H diff --git a/test/std/utilities/tuple/tuple.tuple/alloc_last.h b/test/std/utilities/tuple/tuple.tuple/alloc_last.h new file mode 100644 index 0000000000000..71a9b9e97acc7 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/alloc_last.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef ALLOC_LAST_H +#define ALLOC_LAST_H + +#include <cassert> + +#include "allocators.h" + +struct alloc_last +{ + static bool allocator_constructed; + + typedef A1<int> allocator_type; + + int data_; + + alloc_last() : data_(0) {} + alloc_last(int d) : data_(d) {} + alloc_last(const A1<int>& a) + : data_(0) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_last(int d, const A1<int>& a) + : data_(d) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_last(const alloc_last& d, const A1<int>& a) + : data_(d.data_) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + ~alloc_last() {data_ = -1;} + + friend bool operator==(const alloc_last& x, const alloc_last& y) + {return x.data_ == y.data_;} + friend bool operator< (const alloc_last& x, const alloc_last& y) + {return x.data_ < y.data_;} +}; + +bool alloc_last::allocator_constructed = false; + +#endif // ALLOC_LAST_H diff --git a/test/std/utilities/tuple/tuple.tuple/empty_member.pass.cpp b/test/std/utilities/tuple/tuple.tuple/empty_member.pass.cpp new file mode 100644 index 0000000000000..1e7243b5f501d --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/empty_member.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// UNSUPPORTED: c++98, c++03 + +// This is not a portable test + +#include <tuple> + +struct A {}; + +struct B {}; + +int main() +{ + { + typedef std::tuple<int, A> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, B, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<int, A, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp new file mode 100644 index 0000000000000..a3d14487b47d3 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> +// tuple& operator=(const pair<U1, U2>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<double, char> T0; + typedef std::tuple<int, short> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == short('a')); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp new file mode 100644 index 0000000000000..2dde6b5521f2d --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// tuple& operator=(const tuple<UTypes...>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i = 0) : id_(i) {} +}; + +struct D + : B +{ + explicit D(int i = 0) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + D d2(2); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d2); + T1 t1(1.5, 'b', d); + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp new file mode 100644 index 0000000000000..11bfdd0c94a98 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// tuple& operator=(tuple<UTypes...>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <memory> +#include <utility> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i= 0) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + D d2(2); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d2); + T1 t1(1.5, 'b', d); + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, std::unique_ptr<D>> T0; + typedef std::tuple<int, int, std::unique_ptr<B>> T1; + T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp new file mode 100644 index 0000000000000..5911391d6cd2b --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(const tuple& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(2)); + T t; + t = t0; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp new file mode 100644 index 0000000000000..d5d0207797268 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(const tuple& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t; + t = t0; + } + { + typedef std::tuple<int> T; + T t0(2); + T t; + t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<int, char> T; + T t0(2, 'a'); + T t; + t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple<int, char, std::string> T; + const T t0(2, 'a', "some text"); + T t; + t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + assert(std::get<2>(t) == "some text"); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp new file mode 100644 index 0000000000000..fc5e41ad569d8 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(tuple&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t; + t = std::move(t0); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp new file mode 100644 index 0000000000000..812e6329bb3e3 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> +// tuple& operator=(pair<U1, U2>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i = 0) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<double, std::unique_ptr<D>> T0; + typedef std::tuple<int, std::unique_ptr<B>> T1; + T0 t0(2.5, std::unique_ptr<D>(new D(3))); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp new file mode 100644 index 0000000000000..08d1304f99421 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Tuple, __tuple_assignable<Tuple, tuple> > +// tuple & operator=(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array when it doesn't match the size of the tuple. + +#include <array> +#include <tuple> + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array<char, 1256> array_t; +typedef std::tuple<array_t> tuple_t; + +int main() +{ + array_t arr; + tuple_t tup; + tup = arr; +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp new file mode 100644 index 0000000000000..b9497bea56771 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +// UNSUPPORTED: c++98, c++03 + +/* + This is testing an extension whereby only Types having an explicit conversion + from UTypes are bound by the explicit tuple constructor. +*/ + +#include <tuple> +#include <cassert> + +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + explicit MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} +}; + +int main() +{ + { + std::tuple<MoveOnly> t = 1; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp new file mode 100644 index 0000000000000..817cc8f109905 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> +#include <type_traits> + +#include "MoveOnly.h" + +#if _LIBCPP_STD_VER > 11 + +struct Empty {}; +struct A +{ + int id_; + explicit constexpr A(int i) : id_(i) {} +}; + +#endif + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple type. + typedef std::tuple<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple<MoveOnly> t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0), + MoveOnly(1), + MoveOnly(2)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // extensions + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0), + MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<Empty> t0{Empty()}; + } + { + constexpr std::tuple<A, A> t(3, 2); + static_assert(std::get<0>(t).id_ == 3, ""); + } +#endif + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp new file mode 100644 index 0000000000000..39776822cbda4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "DefaultOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<> t(std::allocator_arg, A1<int>()); + } + { + std::tuple<int> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == 0); + } + { + std::tuple<DefaultOnly> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == DefaultOnly()); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first()); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first> t(std::allocator_arg, A1<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp new file mode 100644 index 0000000000000..3929965cd2735 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, UTypes&&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple + typedef std::tuple<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple<MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + MoveOnly(0), + 1, 2); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5), 1, 2, 3); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + // extensions + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 0, 1); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp new file mode 100644 index 0000000000000..0f68926376f24 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const Types&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<int> t(std::allocator_arg, A1<int>(), 3); + assert(std::get<0>(t) == 3); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5), alloc_first(3)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first(3)); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5), alloc_last(3)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + std::tuple<int, alloc_first> t(std::allocator_arg, A1<int>(5), + 10, alloc_first(15)); + assert(std::get<0>(t) == 10); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(15)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp new file mode 100644 index 0000000000000..c5941618180d3 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::pair<double, int> T0; + typedef std::tuple<int, double> T1; + T0 t0(2, 3); + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, double> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp new file mode 100644 index 0000000000000..8acfde7a98eb1 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::tuple<double, int, int> T0; + typedef std::tuple<int, alloc_first, alloc_last> T1; + T0 t0(1.5, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1) == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp new file mode 100644 index 0000000000000..c862d3b64d56f --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<std::unique_ptr<D>> T0; + typedef std::tuple<std::unique_ptr<B>> T1; + T0 t0(std::unique_ptr<D>(new D(3))); + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(std::get<0>(t1)->id_ == 3); + } + { + typedef std::tuple<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } + { + typedef std::tuple<int, int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1; + T0 t0(1, 2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp new file mode 100644 index 0000000000000..14e127e59ba91 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const tuple&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1<int>(), t0); + } + { + typedef std::tuple<int> T; + T t0(2); + T t(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first> T; + T t0(2); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_last> T; + T t0(2); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first, alloc_last> T; + T t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 3); + } + { + typedef std::tuple<int, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp new file mode 100644 index 0000000000000..54d3f7ee0c079 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, tuple&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1<int>(), std::move(t0)); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t(std::allocator_arg, A1<int>(), std::move(t0)); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<alloc_first> T; + T t0(1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<alloc_last> T; + T t0(1); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first> T; + T t0(0 ,1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp new file mode 100644 index 0000000000000..03e9ab2f60269 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp new file mode 100644 index 0000000000000..00e2af265b360 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int*> t = 0; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp new file mode 100644 index 0000000000000..bbadf8de16001 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + + +template <class ...> +struct never { + enum { value = 0 }; +}; + +struct NoValueCtor +{ + NoValueCtor() : id(++count) {} + NoValueCtor(NoValueCtor const & other) : id(other.id) { ++count; } + + // The constexpr is required to make is_constructible instantiate this template. + // The explicit is needed to test-around a similar bug with is_convertible. + template <class T> + constexpr explicit NoValueCtor(T) + { static_assert(never<T>::value, "This should not be instantiated"); } + + static int count; + int id; +}; + +int NoValueCtor::count = 0; + + +struct NoValueCtorEmpty +{ + NoValueCtorEmpty() {} + NoValueCtorEmpty(NoValueCtorEmpty const &) {} + + template <class T> + constexpr explicit NoValueCtorEmpty(T) + { static_assert(never<T>::value, "This should not be instantiated"); } +}; + +int main() +{ + { + std::tuple<int> t(2); + assert(std::get<0>(t) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int> t(2); + static_assert(std::get<0>(t) == 2, ""); + } + { + constexpr std::tuple<int> t; + static_assert(std::get<0>(t) == 0, ""); + } +#endif + { + std::tuple<int, char*> t(2, 0); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int, char*> t(2, nullptr); + static_assert(std::get<0>(t) == 2, ""); + static_assert(std::get<1>(t) == nullptr, ""); + } +#endif + { + std::tuple<int, char*> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + } + // __tuple_leaf<T> uses is_constructible<T, U> to disable its explicit converting + // constructor overload __tuple_leaf(U &&). Evaluating is_constructible can cause a compile error. + // This overload is evaluated when __tuple_leafs copy or move ctor is called. + // This checks that is_constructible is not evaluated when U == __tuple_leaf. + { + std::tuple<int, NoValueCtor, int, int> t(1, NoValueCtor(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t).id == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + { + std::tuple<int, NoValueCtorEmpty, int, int> t(1, NoValueCtorEmpty(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + // extensions + { + std::tuple<int, char*, std::string> t(2); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, double> t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + assert(std::get<3>(t) == 0.0); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp new file mode 100644 index 0000000000000..68b3fbd0dd9e4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int, char*, std::string, double&> t(2, nullptr, "text"); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp new file mode 100644 index 0000000000000..740b6589e5114 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(const pair<U1, U2>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<double, char> T0; + typedef std::tuple<int, short> T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == short('a')); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<double, char> P0; + typedef std::tuple<int, short> T1; + constexpr P0 p0(2.5, 'a'); + constexpr T1 t1 = p0; + static_assert(std::get<0>(t1) != std::get<0>(p0), ""); + static_assert(std::get<1>(t1) == std::get<1>(p0), ""); + static_assert(std::get<0>(t1) == 2, ""); + static_assert(std::get<1>(t1) == short('a'), ""); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp new file mode 100644 index 0000000000000..5ad4f9227f481 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(const tuple<UTypes...>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <string> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +#if _LIBCPP_STD_VER > 11 + +struct A +{ + int id_; + + constexpr A(int i) : id_(i) {} + friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;} +}; + +struct C +{ + int id_; + + constexpr explicit C(int i) : id_(i) {} + friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;} +}; + +#endif + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<double> T0; + typedef std::tuple<A> T1; + constexpr T0 t0(2.5); + constexpr T1 t1 = t0; + static_assert(std::get<0>(t1) == 2, ""); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<C> T1; + constexpr T0 t0(2); + constexpr T1 t1{t0}; + static_assert(std::get<0>(t1) == C(2), ""); + } +#endif + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d); + T1 t1 = t0; + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, int> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', 3); + T1 t1(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp new file mode 100644 index 0000000000000..3a6abd3a95af4 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(tuple<UTypes...>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d); + T1 t1 = std::move(t0); + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, std::unique_ptr<D>> T0; + typedef std::tuple<int, int, std::unique_ptr<B>> T1; + T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp new file mode 100644 index 0000000000000..1937f49efa76a --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(2)); + T t = t0; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp new file mode 100644 index 0000000000000..783c9d1f06a8b --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = t0; + ((void)t); // Prevent unused warning + } + { + typedef std::tuple<int> T; + T t0(2); + T t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<int, char> T; + T t0(2, 'a'); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple<int, char, std::string> T; + const T t0(2, 'a', "some text"); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + assert(std::get<2>(t) == "some text"); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<int> T; + constexpr T t0(2); + constexpr T t = t0; + static_assert(std::get<0>(t) == 2, ""); + } + { + typedef std::tuple<Empty> T; + constexpr T t0; + constexpr T t = t0; + constexpr Empty e = std::get<0>(t); + ((void)e); // Prevent unused warning + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp new file mode 100644 index 0000000000000..d282c9c68a42d --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// constexpr tuple(); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> +#include <type_traits> + +#include "DefaultOnly.h" + +struct NoDefault { + NoDefault() = delete; + explicit NoDefault(int) { } +}; + +struct NoExceptDefault { + NoExceptDefault() noexcept = default; +}; + +struct ThrowingDefault { + ThrowingDefault() { } +}; + +struct IllFormedDefault { + IllFormedDefault(int x) : value(x) {} + template <bool Pred = false> + constexpr IllFormedDefault() { + static_assert(Pred, + "The default constructor should not be instantiated"); + } + int value; +}; + +int main() +{ + { + std::tuple<> t; + } + { + std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, DefaultOnly> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + assert(std::get<3>(t) == DefaultOnly()); + } + { + // See bug #21157. + static_assert(!std::is_default_constructible<std::tuple<NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<DefaultOnly, NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<NoDefault, DefaultOnly, NoDefault>>(), ""); + } + { + static_assert(noexcept(std::tuple<NoExceptDefault>()), ""); + static_assert(noexcept(std::tuple<NoExceptDefault, NoExceptDefault>()), ""); + + static_assert(!noexcept(std::tuple<ThrowingDefault, NoExceptDefault>()), ""); + static_assert(!noexcept(std::tuple<NoExceptDefault, ThrowingDefault>()), ""); + static_assert(!noexcept(std::tuple<ThrowingDefault, ThrowingDefault>()), ""); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::tuple<> t; + } + { + constexpr std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + constexpr std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + // Check that the SFINAE on the default constructor is not evaluted when + // it isn't needed. If the default constructor is evaluted then this test + // should fail to compile. + IllFormedDefault v(0); + std::tuple<IllFormedDefault> t(v); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp new file mode 100644 index 0000000000000..0cda96846f717 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(tuple&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <cassert> + +#include "MoveOnly.h" + +struct ConstructsWithTupleLeaf +{ + ConstructsWithTupleLeaf() {} + + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} + + template <class T> + ConstructsWithTupleLeaf(T t) + { assert(false); } +}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = std::move(t0); + ((void)t); // Prevent unused warning + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // A bug in tuple caused __tuple_leaf to use its explicit converting constructor + // as its move constructor. This tests that ConstructsWithTupleLeaf is not called + // (w/ __tuple_leaf) + { + typedef std::tuple<ConstructsWithTupleLeaf> d_t; + d_t d((ConstructsWithTupleLeaf())); + d_t d2(static_cast<d_t &&>(d)); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp new file mode 100644 index 0000000000000..2dfbaff6cc1a7 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(pair<U1, U2>&& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<double, std::unique_ptr<D>> T0; + typedef std::tuple<int, std::unique_ptr<B>> T1; + T0 t0(2.5, std::unique_ptr<D>(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp new file mode 100644 index 0000000000000..c069a0ba20eae --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Tuple, __tuple_convertible<Tuple, tuple> > +// tuple(Tuple &&); +// +// template <class Tuple, __tuple_constructible<Tuple, tuple> > +// tuple(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array. + +#include <array> +#include <tuple> + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array<char, 1256> array_t; +typedef std::tuple<array_t> tuple_t; + +int main() +{ + array_t arr; + tuple_t tup(arr); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp new file mode 100644 index 0000000000000..0e556b1b6c8e0 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template<class... Types> +// tuple<Types&&...> forward_as_tuple(Types&&... t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <type_traits> +#include <cassert> + +template <class Tuple> +void +test0(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 0, ""); +} + +template <class Tuple> +void +test1a(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 1, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, ""); + assert(std::get<0>(t) == 1); +} + +template <class Tuple> +void +test1b(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 1, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, ""); + assert(std::get<0>(t) == 2); +} + +template <class Tuple> +void +test2a(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 2, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, ""); + static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, ""); + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == 'a'); +} + +#if _LIBCPP_STD_VER > 11 +template <class Tuple> +constexpr int +test3(const Tuple& t) +{ + return std::tuple_size<Tuple>::value; +} +#endif + +int main() +{ + { + test0(std::forward_as_tuple()); + } + { + test1a(std::forward_as_tuple(1)); + } + { + int i = 2; + test1b(std::forward_as_tuple(i)); + } + { + double i = 2.5; + char c = 'a'; + test2a(std::forward_as_tuple(i, c)); +#if _LIBCPP_STD_VER > 11 + static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" ); +#endif + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp new file mode 100644 index 0000000000000..2ee96dc7ebf45 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... Types> +// tuple<VTypes...> make_tuple(Types&&... t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <functional> +#include <cassert> + +int main() +{ + { + int i = 0; + float j = 0; + std::tuple<int, int&, float&> t = std::make_tuple(1, std::ref(i), + std::ref(j)); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 0); + assert(std::get<2>(t) == 0); + i = 2; + j = 3.5; + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3.5); + std::get<1>(t) = 0; + std::get<2>(t) = 0; + assert(i == 0); + assert(j == 0); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr auto t1 = std::make_tuple(0, 1, 3.14); + constexpr int i1 = std::get<1>(t1); + constexpr double d1 = std::get<2>(t1); + static_assert (i1 == 1, "" ); + static_assert (d1 == 3.14, "" ); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp new file mode 100644 index 0000000000000..52ecd249402f9 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... Types> +// tuple<Types&...> tie(Types&... t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + int i = 0; + std::string s; + std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++"); + assert(i == 42); + assert(s == "C++"); + } +#if _LIBCPP_STD_VER > 11 + { + static constexpr int i = 42; + static constexpr double f = 1.1; + constexpr std::tuple<const int &, const double &> t = std::tie(i, f); + static_assert ( std::get<0>(t) == 42, "" ); + static_assert ( std::get<1>(t) == 1.1, "" ); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp new file mode 100644 index 0000000000000..770edcaca5e19 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp @@ -0,0 +1,241 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <array> +#include <string> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + std::tuple<> t = std::tuple_cat(); + ((void)t); // Prevent unused warning + } + { + std::tuple<> t1; + std::tuple<> t2 = std::tuple_cat(t1); + ((void)t2); // Prevent unused warning + } + { + std::tuple<> t = std::tuple_cat(std::tuple<>()); + ((void)t); // Prevent unused warning + } + { + std::tuple<> t = std::tuple_cat(std::array<int, 0>()); + ((void)t); // Prevent unused warning + } + { + std::tuple<int> t1(1); + std::tuple<int> t = std::tuple_cat(t1); + assert(std::get<0>(t) == 1); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<> t = std::tuple_cat(); + ((void)t); // Prevent unused warning + } + { + constexpr std::tuple<> t1; + constexpr std::tuple<> t2 = std::tuple_cat(t1); + ((void)t2); // Prevent unused warning + } + { + constexpr std::tuple<> t = std::tuple_cat(std::tuple<>()); + ((void)t); // Prevent unused warning + } + { + constexpr std::tuple<> t = std::tuple_cat(std::array<int, 0>()); + ((void)t); // Prevent unused warning + } + { + constexpr std::tuple<int> t1(1); + constexpr std::tuple<int> t = std::tuple_cat(t1); + static_assert(std::get<0>(t) == 1, ""); + } + { + constexpr std::tuple<int> t1(1); + constexpr std::tuple<int, int> t = std::tuple_cat(t1, t1); + static_assert(std::get<0>(t) == 1, ""); + static_assert(std::get<1>(t) == 1, ""); + } +#endif + { + std::tuple<int, MoveOnly> t = + std::tuple_cat(std::tuple<int, MoveOnly>(1, 2)); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + } + { + std::tuple<int, int, int> t = std::tuple_cat(std::array<int, 3>()); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 0); + assert(std::get<2>(t) == 0); + } + { + std::tuple<int, MoveOnly> t = std::tuple_cat(std::pair<int, MoveOnly>(2, 1)); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 1); + } + + { + std::tuple<> t1; + std::tuple<> t2; + std::tuple<> t3 = std::tuple_cat(t1, t2); + ((void)t3); // Prevent unused warning + } + { + std::tuple<> t1; + std::tuple<int> t2(2); + std::tuple<int> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == 2); + } + { + std::tuple<> t1; + std::tuple<int> t2(2); + std::tuple<int> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + } + { + std::tuple<int*> t1; + std::tuple<int> t2(2); + std::tuple<int*, int> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 2); + } + { + std::tuple<int*> t1; + std::tuple<int> t2(2); + std::tuple<int, int*> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == nullptr); + } + { + std::tuple<int*> t1; + std::tuple<int, double> t2(2, 3.5); + std::tuple<int*, int, double> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == 3.5); + } + { + std::tuple<int*> t1; + std::tuple<int, double> t2(2, 3.5); + std::tuple<int, double, int*> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == 3.5); + assert(std::get<2>(t3) == nullptr); + } + { + std::tuple<int*, MoveOnly> t1(nullptr, 1); + std::tuple<int, double> t2(2, 3.5); + std::tuple<int*, MoveOnly, int, double> t3 = + std::tuple_cat(std::move(t1), t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 1); + assert(std::get<2>(t3) == 2); + assert(std::get<3>(t3) == 3.5); + } + { + std::tuple<int*, MoveOnly> t1(nullptr, 1); + std::tuple<int, double> t2(2, 3.5); + std::tuple<int, double, int*, MoveOnly> t3 = + std::tuple_cat(t2, std::move(t1)); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == 3.5); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 1); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::tuple<>(), + std::move(t1), + std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), + std::tuple<>(), + std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), + std::move(t2), + std::tuple<>()); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly, int> t3 = + std::tuple_cat(std::move(t1), + std::move(t2), + std::tuple<int>(5)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + assert(std::get<4>(t3) == 5); + } + { + // See bug #19616. + auto t1 = std::tuple_cat( + std::make_tuple(std::make_tuple(1)), + std::make_tuple() + ); + assert(t1 == std::make_tuple(std::make_tuple(1))); + + auto t2 = std::tuple_cat( + std::make_tuple(std::make_tuple(1)), + std::make_tuple(std::make_tuple(2)) + ); + assert(t2 == std::make_tuple(std::make_tuple(1), std::make_tuple(2))); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.cpp new file mode 100644 index 0000000000000..490283e7abdd0 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type const& +// get(const tuple<Types...>& t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + const T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + assert(d == 2.5); + + std::get<1>(t) = "four"; + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp new file mode 100644 index 0000000000000..e21768cb6f5fd --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type const& +// get(const tuple<Types...>& t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<int> T; + const T t(3); + assert(std::get<0>(t) == 3); + } + { + typedef std::tuple<std::string, int> T; + const T t("high", 5); + assert(std::get<0>(t) == "high"); + assert(std::get<1>(t) == 5); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<double, int> T; + constexpr T t(2.718, 5); + static_assert(std::get<0>(t) == 2.718, ""); + static_assert(std::get<1>(t) == 5, ""); + } + { + typedef std::tuple<Empty> T; + constexpr T t{Empty()}; + constexpr Empty e = std::get<0>(t); + ((void)e); // Prevent unused warning + } +#endif + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + const T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + assert(d == 2.5); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp new file mode 100644 index 0000000000000..1c2b17ad88325 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type& +// get(tuple<Types...>& t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +#if __cplusplus > 201103L + +struct Empty {}; + +struct S { + std::tuple<int, Empty> a; + int k; + Empty e; + constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {} + }; + +constexpr std::tuple<int, int> getP () { return { 3, 4 }; } +#endif + +int main() +{ + { + typedef std::tuple<int> T; + T t(3); + assert(std::get<0>(t) == 3); + std::get<0>(t) = 2; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<std::string, int> T; + T t("high", 5); + assert(std::get<0>(t) == "high"); + assert(std::get<1>(t) == 5); + std::get<0>(t) = "four"; + std::get<1>(t) = 4; + assert(std::get<0>(t) == "four"); + assert(std::get<1>(t) == 4); + } + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + std::get<1>(t) = "four"; + std::get<2>(t) = 4; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "four"); + assert(std::get<2>(t) == 4); + assert(d == 2.5); + } +#if _LIBCPP_STD_VER > 11 + { // get on an rvalue tuple + static_assert ( std::get<0> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 0, "" ); + static_assert ( std::get<1> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 1, "" ); + static_assert ( std::get<2> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 2, "" ); + static_assert ( std::get<3> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 3, "" ); + static_assert(S().k == 1, ""); + static_assert(std::get<1>(getP()) == 4, ""); + } +#endif + +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp new file mode 100644 index 0000000000000..6c456d4308269 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type&& +// get(tuple<Types...>&& t); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ + { + typedef std::tuple<std::unique_ptr<int> > T; + T t(std::unique_ptr<int>(new int(3))); + std::unique_ptr<int> p = std::get<0>(std::move(t)); + assert(*p == 3); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp new file mode 100644 index 0000000000000..aa020dab47c7c --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + { + auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }}; + assert ( std::get<int>(t1) == 42 ); // find at the beginning + assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle + assert ( std::get<cf>(t1).real() == 1 ); // find at the end + assert ( std::get<cf>(t1).imag() == 2 ); + } + + { + auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }}; +// get<int> would fail! + assert ( std::get<std::string>(t2) == "Hi" ); + assert (( std::get<cf>(t2) == cf{ 1,2 } )); + } + + { + constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; + static_assert ( std::get<int>(p5) == 1, "" ); + static_assert ( std::get<const int>(p5) == 2, "" ); + } + + { + const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; + const int &i1 = std::get<int>(p5); + const int &i2 = std::get<const int>(p5); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + typedef std::unique_ptr<int> upint; + std::tuple<upint> t(upint(new int(4))); + upint p = std::get<upint>(std::move(t)); // get rvalue + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp new file mode 100644 index 0000000000000..85c32ca6d4955 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<int, std::string> ( 42, "Hi" ); + assert (( std::get<cf>(t1) == cf {1,2} )); // no such type +#else +#error +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp new file mode 100644 index 0000000000000..0a8d5829d02b1 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<int, int, std::string, cf> ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get<int>(t1) == 42 ); // two ints here +#else +#error +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp new file mode 100644 index 0000000000000..0a4550f387dc0 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<double, int, std::string, cf, int> ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get<int>(t1) == 42 ); // two ints here (one at the end) +#else +#error +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp new file mode 100644 index 0000000000000..ffc715fe9a5bd --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +#include <tuple> +#include <string> +#include <memory> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr<int> upint; + std::tuple<upint> t(upint(new int(4))); + upint p = std::get<upint>(t); +#else +#error +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp new file mode 100644 index 0000000000000..d8a72c617cb5c --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// class tuple_element<I, tuple<Types...> > +// { +// public: +// typedef Ti type; +// }; +// +// LWG #2212 says that tuple_size and tuple_element must be +// available after including <utility> + +#include <array> +#include <type_traits> + +template <class T, std::size_t N, class U, size_t idx> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), ""); +} + +int main() +{ + test<std::array<int, 5>, 5, int, 0>(); + test<std::array<int, 5>, 5, int, 1>(); + test<std::array<const char *, 4>, 4, const char *, 3>(); + test<std::array<volatile int, 4>, 4, volatile int, 3>(); + test<std::array<char *, 3>, 3, char *, 1>(); + test<std::array<char *, 3>, 3, char *, 2>(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.pass.cpp new file mode 100644 index 0000000000000..8c8357d95d994 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// class tuple_size<tuple<Types...>> +// : public integral_constant<size_t, sizeof...(Types)> { }; +// +// LWG #2212 says that tuple_size and tuple_element must be +// available after including <utility> + +#include <utility> +#include <type_traits> + +template <class T, std::size_t N, class U, size_t idx> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), ""); +} + +int main() +{ + test<std::pair<int, int>, 2, int, 0>(); + test<std::pair<int, int>, 2, int, 1>(); + test<std::pair<const int, int>, 2, int, 1>(); + test<std::pair<int, volatile int>, 2, volatile int, 1>(); + test<std::pair<char *, int>, 2, char *, 0>(); + test<std::pair<char *, int>, 2, int, 1>(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp new file mode 100644 index 0000000000000..42e4fab88ffa2 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// class tuple_element<I, tuple<Types...> > +// { +// public: +// typedef Ti type; +// }; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <type_traits> + +template <class T, std::size_t N, class U> +void test() +{ + static_assert((std::is_same<typename std::tuple_element<N, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, const volatile T>::type, const volatile U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<typename std::tuple_element_t<N, T>, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, const T>, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, volatile T>, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, const volatile T>, const volatile U>::value), ""); +#endif +} + +int main() +{ + test<std::tuple<int>, 0, int>(); + test<std::tuple<char, int>, 0, char>(); + test<std::tuple<char, int>, 1, int>(); + test<std::tuple<int*, char, int>, 0, int*>(); + test<std::tuple<int*, char, int>, 1, char>(); + test<std::tuple<int*, char, int>, 2, int>(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp new file mode 100644 index 0000000000000..49b4215a19563 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// class tuple_size<tuple<Types...>> +// : public integral_constant<size_t, sizeof...(Types)> { }; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <type_traits> + +template <class T, std::size_t N> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); +} + +int main() +{ + test<std::tuple<>, 0>(); + test<std::tuple<int>, 1>(); + test<std::tuple<char, int>, 2>(); + test<std::tuple<char, char*, int>, 3>(); +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp new file mode 100644 index 0000000000000..0d25edc4547b1 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... TTypes, class... UTypes> +// bool +// operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T1; + typedef std::tuple<> T2; + const T1 t1; + const T2 t2; + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1.1); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, char(2)); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, char(3)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, char(2)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, char(3)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 3); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 4); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 3, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 3, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1.1, 3, 2); + static_assert(!(t1 == t2), ""); + static_assert(t1 != t2, ""); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp new file mode 100644 index 0000000000000..eac84a9c35f6a --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp @@ -0,0 +1,210 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... TTypes, class... UTypes> +// bool +// operator<(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator>(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator<=(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator>=(const tuple<TTypes...>& t, const tuple<UTypes...>& u); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T1; + typedef std::tuple<> T2; + const T1 t1; + const T2 t2; + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(0.9); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1.1); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 2); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(0.9, 2); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, 2); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 1); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 3); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(0.9, 2, 3); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 1, 3); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 2); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 4); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1, 2, 4); + static_assert( (t1 < t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 > t2), ""); + static_assert(!(t1 >= t2), ""); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..dcae606129fa3 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// void swap(tuple<Types...>& x, tuple<Types...>& y); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t1; + swap(t0, t1); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t1(MoveOnly(1)); + swap(t0, t1); + assert(std::get<0>(t0) == 1); + assert(std::get<0>(t1) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t1(MoveOnly(2), MoveOnly(3)); + swap(t0, t1); + assert(std::get<0>(t0) == 2); + assert(std::get<1>(t0) == 3); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5)); + swap(t0, t1); + assert(std::get<0>(t0) == 3); + assert(std::get<1>(t0) == 4); + assert(std::get<2>(t0) == 5); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + assert(std::get<2>(t1) == 2); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp new file mode 100644 index 0000000000000..6749f592aa308 --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// void swap(tuple& rhs); + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t1; + t0.swap(t1); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t1(MoveOnly(1)); + t0.swap(t1); + assert(std::get<0>(t0) == 1); + assert(std::get<0>(t1) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t1(MoveOnly(2), MoveOnly(3)); + t0.swap(t1); + assert(std::get<0>(t0) == 2); + assert(std::get<1>(t0) == 3); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5)); + t0.swap(t1); + assert(std::get<0>(t0) == 3); + assert(std::get<1>(t0) == 4); + assert(std::get<2>(t0) == 5); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + assert(std::get<2>(t1) == 2); + } +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.pass.cpp new file mode 100644 index 0000000000000..ddaf52fead31b --- /dev/null +++ b/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types, class Alloc> +// struct uses_allocator<tuple<Types...>, Alloc> : true_type { }; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <type_traits> + +struct A {}; + +int main() +{ + { + typedef std::tuple<> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<char, int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<double&, char, int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } +} diff --git a/test/std/utilities/tuple/version.pass.cpp b/test/std/utilities/tuple/version.pass.cpp new file mode 100644 index 0000000000000..2fdbb5d2784a8 --- /dev/null +++ b/test/std/utilities/tuple/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +#include <tuple> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/type.index/type.index.hash/hash.pass.cpp b/test/std/utilities/type.index/type.index.hash/hash.pass.cpp new file mode 100644 index 0000000000000..c5ffacfa37e9c --- /dev/null +++ b/test/std/utilities/type.index/type.index.hash/hash.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// template <> +// struct hash<type_index> +// : public unary_function<type_index, size_t> +// { +// size_t operator()(type_index index) const; +// }; + +#include <typeindex> +#include <cassert> + +int main() +{ + typedef std::hash<std::type_index> H; + static_assert((std::is_same<typename H::argument_type, std::type_index>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + + std::type_index t1 = typeid(int); + assert(std::hash<std::type_index>()(t1) == t1.hash_code()); +} diff --git a/test/std/utilities/type.index/type.index.members/ctor.pass.cpp b/test/std/utilities/type.index/type.index.members/ctor.pass.cpp new file mode 100644 index 0000000000000..e5183eb87a77b --- /dev/null +++ b/test/std/utilities/type.index/type.index.members/ctor.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// type_index(const type_info& rhs); + +#include <typeinfo> +#include <typeindex> +#include <cassert> + +int main() +{ + std::type_info const & info = typeid(int); + std::type_index t1(info); + assert(t1.name() == info.name()); +} diff --git a/test/std/utilities/type.index/type.index.members/eq.pass.cpp b/test/std/utilities/type.index/type.index.members/eq.pass.cpp new file mode 100644 index 0000000000000..b6bbd1d237236 --- /dev/null +++ b/test/std/utilities/type.index/type.index.members/eq.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// bool operator==(const type_index& rhs) const; +// bool operator!=(const type_index& rhs) const; + +#include <typeindex> +#include <cassert> + +int main() +{ + std::type_index t1 = typeid(int); + std::type_index t2 = typeid(int); + std::type_index t3 = typeid(long); + assert(t1 == t2); + assert(t1 != t3); +} diff --git a/test/std/utilities/type.index/type.index.members/hash_code.pass.cpp b/test/std/utilities/type.index/type.index.members/hash_code.pass.cpp new file mode 100644 index 0000000000000..b4f3168300654 --- /dev/null +++ b/test/std/utilities/type.index/type.index.members/hash_code.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// size_t hash_code() const; + +#include <typeindex> +#include <cassert> + +int main() +{ + const std::type_info& ti = typeid(int); + std::type_index t1 = typeid(int); + assert(t1.hash_code() == ti.hash_code()); +} diff --git a/test/std/utilities/type.index/type.index.members/lt.pass.cpp b/test/std/utilities/type.index/type.index.members/lt.pass.cpp new file mode 100644 index 0000000000000..c099d1c56378d --- /dev/null +++ b/test/std/utilities/type.index/type.index.members/lt.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// bool operator< (const type_index& rhs) const; +// bool operator<=(const type_index& rhs) const; +// bool operator> (const type_index& rhs) const; +// bool operator>=(const type_index& rhs) const; + +#include <typeindex> +#include <cassert> + +int main() +{ + std::type_index t1 = typeid(int); + std::type_index t2 = typeid(int); + std::type_index t3 = typeid(long); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + if (t1 < t3) + { + assert( (t1 < t3)); + assert( (t1 <= t3)); + assert(!(t1 > t3)); + assert(!(t1 >= t3)); + } + else + { + assert(!(t1 < t3)); + assert(!(t1 <= t3)); + assert( (t1 > t3)); + assert( (t1 >= t3)); + } +} diff --git a/test/std/utilities/type.index/type.index.members/name.pass.cpp b/test/std/utilities/type.index/type.index.members/name.pass.cpp new file mode 100644 index 0000000000000..44ee2151915be --- /dev/null +++ b/test/std/utilities/type.index/type.index.members/name.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// const char* name() const; + +#include <typeindex> +#include <string> +#include <cassert> + +int main() +{ + const std::type_info& ti = typeid(int); + std::type_index t1 = typeid(int); + assert(std::string(t1.name()) == ti.name()); +} diff --git a/test/std/utilities/type.index/type.index.overview/copy_assign.pass.cpp b/test/std/utilities/type.index/type.index.overview/copy_assign.pass.cpp new file mode 100644 index 0000000000000..234e26b495f9f --- /dev/null +++ b/test/std/utilities/type.index/type.index.overview/copy_assign.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// type_index& operator=(const type_index& ti); + +#include <typeindex> +#include <cassert> + +int main() +{ + std::type_index t1(typeid(int)); + std::type_index t2(typeid(double)); + assert(t2 != t1); + t2 = t1; + assert(t2 == t1); +} diff --git a/test/std/utilities/type.index/type.index.overview/copy_ctor.pass.cpp b/test/std/utilities/type.index/type.index.overview/copy_ctor.pass.cpp new file mode 100644 index 0000000000000..499c4b63b06f4 --- /dev/null +++ b/test/std/utilities/type.index/type.index.overview/copy_ctor.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// class type_index + +// type_index(const type_index& ti); + +#include <typeindex> +#include <cassert> + +int main() +{ + std::type_index t1(typeid(int)); + std::type_index t2 = t1; + assert(t2 == t1); +} diff --git a/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp b/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp new file mode 100644 index 0000000000000..6d353f1d30574 --- /dev/null +++ b/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +// struct hash<type_index> +// : public unary_function<type_index, size_t> +// { +// size_t operator()(type_index index) const; +// }; + +#include <typeindex> +#include <type_traits> + +int main() +{ + typedef std::hash<std::type_index> H; + static_assert((std::is_same<typename H::argument_type, std::type_index>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); +} diff --git a/test/std/utilities/type.index/version.pass.cpp b/test/std/utilities/type.index/version.pass.cpp new file mode 100644 index 0000000000000..26f462042fd33 --- /dev/null +++ b/test/std/utilities/type.index/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <typeindex> + +#include <typeindex> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/utilities/utilities.general/nothing_to_do.pass.cpp b/test/std/utilities/utilities.general/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utilities.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/allocator.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/allocator.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/allocator.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/hash.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/hash.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/hash.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/nullablepointer.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/nullablepointer.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/nullablepointer.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/swappable.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/swappable.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/swappable.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility.requirements/utility.arg.requirements/nothing_to_do.pass.cpp b/test/std/utilities/utility.requirements/utility.arg.requirements/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility.requirements/utility.arg.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility/declval/declval.pass.cpp b/test/std/utilities/utility/declval/declval.pass.cpp new file mode 100644 index 0000000000000..81f4df8e8b2b9 --- /dev/null +++ b/test/std/utilities/utility/declval/declval.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T> typename add_rvalue_reference<T>::type declval() noexcept; + +#include <utility> +#include <type_traits> + +class A +{ + A(const A&); + A& operator=(const A&); +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert((std::is_same<decltype(std::declval<A>()), A&&>::value), ""); +#else + static_assert((std::is_same<decltype(std::declval<A>()), A>::value), ""); +#endif +} diff --git a/test/std/utilities/utility/exchange/exchange.pass.cpp b/test/std/utilities/utility/exchange/exchange.pass.cpp new file mode 100644 index 0000000000000..620b4149d1d0b --- /dev/null +++ b/test/std/utilities/utility/exchange/exchange.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// utilities + +// exchange + +#include <utility> +#include <cassert> +#include <string> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + int v = 12; + assert ( std::exchange ( v, 23 ) == 12 ); + assert ( v == 23 ); + assert ( std::exchange ( v, 67.2 ) == 23 ); + assert ( v == 67 ); + + assert ((std::exchange<int, float> ( v, {} )) == 67 ); + assert ( v == 0 ); + + } + + { + bool b = false; + assert ( !std::exchange ( b, true )); + assert ( b ); + } + + { + const std::string s1 ( "Hi Mom!" ); + const std::string s2 ( "Yo Dad!" ); + std::string s3 = s1; // Mom + assert ( std::exchange ( s3, s2 ) == s1 ); + assert ( s3 == s2 ); + assert ( std::exchange ( s3, "Hi Mom!" ) == s2 ); + assert ( s3 == s1 ); + + s3 = s2; // Dad + assert ( std::exchange ( s3, {} ) == s2 ); + assert ( s3.size () == 0 ); + + s3 = s2; // Dad + assert ( std::exchange ( s3, "" ) == s2 ); + assert ( s3.size () == 0 ); + } + +#endif +} diff --git a/test/std/utilities/utility/forward/forward.pass.cpp b/test/std/utilities/utility/forward/forward.pass.cpp new file mode 100644 index 0000000000000..357b36fafa960 --- /dev/null +++ b/test/std/utilities/utility/forward/forward.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> +#include <cassert> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +typedef char one; +struct two {one _[2];}; +struct four {one _[4];}; +struct eight {one _[8];}; + +one test(A&); +two test(const A&); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +four test(A&&); +eight test(const A&&); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + A a; + const A ca = A(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); + static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); +// static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = std::move(23); + static_assert(i1 == 23, "" ); + constexpr int i2 = std::forward<int>(42); + static_assert(i2 == 42, "" ); +#endif +} diff --git a/test/std/utilities/utility/forward/forward1.fail.cpp b/test/std/utilities/utility/forward/forward1.fail.cpp new file mode 100644 index 0000000000000..43884d54bf86b --- /dev/null +++ b/test/std/utilities/utility/forward/forward1.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(source()); // error +} diff --git a/test/std/utilities/utility/forward/forward2.fail.cpp b/test/std/utilities/utility/forward/forward2.fail.cpp new file mode 100644 index 0000000000000..9ff07233fee82 --- /dev/null +++ b/test/std/utilities/utility/forward/forward2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A&>(ca); // error +} diff --git a/test/std/utilities/utility/forward/forward3.fail.cpp b/test/std/utilities/utility/forward/forward3.fail.cpp new file mode 100644 index 0000000000000..7e1e9b38fdc2d --- /dev/null +++ b/test/std/utilities/utility/forward/forward3.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(csource()); // error +} diff --git a/test/std/utilities/utility/forward/forward4.fail.cpp b/test/std/utilities/utility/forward/forward4.fail.cpp new file mode 100644 index 0000000000000..276506f811b5f --- /dev/null +++ b/test/std/utilities/utility/forward/forward4.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(ca); // error +} diff --git a/test/std/utilities/utility/forward/forward5.fail.cpp b/test/std/utilities/utility/forward/forward5.fail.cpp new file mode 100644 index 0000000000000..86c2b5651b90e --- /dev/null +++ b/test/std/utilities/utility/forward/forward5.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(csource()); // error +} diff --git a/test/std/utilities/utility/forward/forward6.fail.cpp b/test/std/utilities/utility/forward/forward6.fail.cpp new file mode 100644 index 0000000000000..1f4b37d946caa --- /dev/null +++ b/test/std/utilities/utility/forward/forward6.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +int main() +{ + A a; + std::forward(a); // error +} diff --git a/test/std/utilities/utility/forward/move_copy.pass.cpp b/test/std/utilities/utility/forward/move_copy.pass.cpp new file mode 100644 index 0000000000000..fa15553f669f0 --- /dev/null +++ b/test/std/utilities/utility/forward/move_copy.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 move + +// UNSUPPORTED: c++98, c++03 + +#include <utility> +#include <cassert> + +int copy_ctor = 0; +int move_ctor = 0; + +class A +{ +public: + + A(const A&) {++copy_ctor;} + A& operator=(const A&); + + A(A&&) {++move_ctor;} + A& operator=(A&&); + + A() {} +}; + +A source() {return A();} +const A csource() {return A();} + +void test(A) {} + +int main() +{ + A a; + const A ca = A(); + + assert(copy_ctor == 0); + assert(move_ctor == 0); + + A a2 = a; + assert(copy_ctor == 1); + assert(move_ctor == 0); + + A a3 = std::move(a); + assert(copy_ctor == 1); + assert(move_ctor == 1); + + A a4 = ca; + assert(copy_ctor == 2); + assert(move_ctor == 1); + + A a5 = std::move(ca); + assert(copy_ctor == 3); + assert(move_ctor == 1); +} diff --git a/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp b/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp new file mode 100644 index 0000000000000..c8375e9d72389 --- /dev/null +++ b/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T> +// typename conditional +// < +// !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, +// const T&, +// T&& +// >::type +// move_if_noexcept(T& x); + +#include <utility> + +#include "test_macros.h" + +class A +{ + A(const A&); + A& operator=(const A&); +public: + + A() {} +#if TEST_STD_VER >= 11 + A(A&&) {} +#endif +}; + +struct legacy +{ + legacy() {} + legacy(const legacy&); +}; + +int main() +{ + int i = 0; + const int ci = 0; + + legacy l; + A a; + const A ca; + +#if TEST_STD_VER >= 11 + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), ""); +#else // C++ < 11 + // libc++ defines decltype to be __typeof__ in C++03. __typeof__ does not + // deduce the reference qualifiers. + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy>::value), ""); +#endif + +#if TEST_STD_VER > 11 + constexpr int i1 = 23; + constexpr int i2 = std::move_if_noexcept(i1); + static_assert(i2 == 23, "" ); +#endif + +} diff --git a/test/std/utilities/utility/forward/move_only.pass.cpp b/test/std/utilities/utility/forward/move_only.pass.cpp new file mode 100644 index 0000000000000..520bf5e5b6a18 --- /dev/null +++ b/test/std/utilities/utility/forward/move_only.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test move + +// UNSUPPORTED: c++98, c++03 + +#include <utility> +#include <cassert> + +class move_only +{ + move_only(const move_only&); + move_only& operator=(const move_only&); +public: + move_only(move_only&&) {} + move_only& operator=(move_only&&) {return *this;} + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only mo; + + test(std::move(mo)); + test(source()); +} diff --git a/test/std/utilities/utility/forward/move_only1.fail.cpp b/test/std/utilities/utility/forward/move_only1.fail.cpp new file mode 100644 index 0000000000000..5e7623a1bd19a --- /dev/null +++ b/test/std/utilities/utility/forward/move_only1.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#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& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(a); +} diff --git a/test/std/utilities/utility/forward/move_only2.fail.cpp b/test/std/utilities/utility/forward/move_only2.fail.cpp new file mode 100644 index 0000000000000..2043f3d4bde7a --- /dev/null +++ b/test/std/utilities/utility/forward/move_only2.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#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& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(ca); +} diff --git a/test/std/utilities/utility/forward/move_only3.fail.cpp b/test/std/utilities/utility/forward/move_only3.fail.cpp new file mode 100644 index 0000000000000..84c83ae48f8ac --- /dev/null +++ b/test/std/utilities/utility/forward/move_only3.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#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& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(std::move(ca)); +} diff --git a/test/std/utilities/utility/forward/move_only4.fail.cpp b/test/std/utilities/utility/forward/move_only4.fail.cpp new file mode 100644 index 0000000000000..5eeca89abe36a --- /dev/null +++ b/test/std/utilities/utility/forward/move_only4.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#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& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(csource()); +} diff --git a/test/std/utilities/utility/operators/rel_ops.pass.cpp b/test/std/utilities/utility/operators/rel_ops.pass.cpp new file mode 100644 index 0000000000000..26e766592f2b0 --- /dev/null +++ b/test/std/utilities/utility/operators/rel_ops.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// test rel_ops + +#include <utility> +#include <cassert> + +struct A +{ + int data_; + + explicit A(int data = -1) : data_(data) {} +}; + +inline +bool +operator == (const A& x, const A& y) +{ + return x.data_ == y.data_; +} + +inline +bool +operator < (const A& x, const A& y) +{ + return x.data_ < y.data_; +} + +int main() +{ + using namespace std::rel_ops; + A a1(1); + A a2(2); + assert(a1 == a1); + assert(a1 != a2); + assert(a1 < a2); + assert(a2 > a1); + assert(a1 <= a1); + assert(a1 <= a2); + assert(a2 >= a2); + assert(a2 >= a1); +} diff --git a/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp b/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp new file mode 100644 index 0000000000000..dbe1c2668665b --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<size_t I, class T1, class T2> +// const typename tuple_element<I, std::pair<T1, T2> >::type& +// get(const pair<T1, T2>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + const P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + std::get<0>(p) = 5; + } +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp new file mode 100644 index 0000000000000..fcda3664d9b62 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<size_t I, class T1, class T2> +// const typename tuple_element<I, std::pair<T1, T2> >::type& +// get(const pair<T1, T2>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + const P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + } + +#if __cplusplus > 201103L + { + typedef std::pair<int, short> P; + constexpr P p1(3, 4); + static_assert(std::get<0>(p1) == 3, ""); + static_assert(std::get<1>(p1) == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp new file mode 100644 index 0000000000000..6d61c47ffbf03 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<size_t I, class T1, class T2> +// typename tuple_element<I, std::pair<T1, T2> >::type& +// get(pair<T1, T2>&); + +#include <utility> +#include <cassert> + +#if __cplusplus > 201103L +struct S { + std::pair<int, int> a; + int k; + constexpr S() : a{1,2}, k(std::get<0>(a)) {} + }; + +constexpr std::pair<int, int> getP () { return { 3, 4 }; } +#endif + +int main() +{ + { + typedef std::pair<int, short> P; + P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + std::get<0>(p) = 5; + std::get<1>(p) = 6; + assert(std::get<0>(p) == 5); + assert(std::get<1>(p) == 6); + } + +#if __cplusplus > 201103L + { + static_assert(S().k == 1, ""); + static_assert(std::get<1>(getP()) == 4, ""); + } +#endif + +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp new file mode 100644 index 0000000000000..aa5ca530913c0 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<size_t I, class T1, class T2> +// typename tuple_element<I, std::pair<T1, T2> >::type&& +// get(pair<T1, T2>&&); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<int>, short> P; + P p(std::unique_ptr<int>(new int(3)), 4); + std::unique_ptr<int> ptr = std::get<0>(std::move(p)); + assert(*ptr == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp new file mode 100644 index 0000000000000..176d58330d165 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +#include <utility> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + { + auto t1 = std::make_pair<int, cf> ( 42, { 1,2 } ); + assert ( std::get<int>(t1) == 42 ); + assert ( std::get<cf>(t1).real() == 1 ); + assert ( std::get<cf>(t1).imag() == 2 ); + } + + { + const std::pair<int, const int> p1 { 1, 2 }; + const int &i1 = std::get<int>(p1); + const int &i2 = std::get<const int>(p1); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + typedef std::unique_ptr<int> upint; + std::pair<upint, int> t(upint(new int(4)), 42); + upint p = std::get<0>(std::move(t)); // get rvalue + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp new file mode 100644 index 0000000000000..27194effe5c32 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_pair<int, double> ( 42, 3.4 ); + assert (( std::get<cf>(t1) == cf {1,2} )); // no such type +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp new file mode 100644 index 0000000000000..f9e3942d7e773 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_pair<int, int> ( 42, 43 ); + assert ( std::get<int>(t1) == 42 ); // two ints +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp new file mode 100644 index 0000000000000..484347345747d --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr<int> upint; + std::pair<upint, int> t(upint(new int(4)), 23); + upint p = std::get<upint>(t); +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp new file mode 100644 index 0000000000000..5ac838b37429d --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// tuple_element<I, pair<T1, T2> >::type + +#include <utility> + +template <class T1, class T2> +void test() +{ + { + typedef T1 Exp1; + typedef T2 Exp2; + typedef std::pair<T1, T2> P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 const Exp1; + typedef T2 const Exp2; + typedef std::pair<T1, T2> const P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 volatile Exp1; + typedef T2 volatile Exp2; + typedef std::pair<T1, T2> volatile P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 const volatile Exp1; + typedef T2 const volatile Exp2; + typedef std::pair<T1, T2> const volatile P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } +} + +int main() +{ + test<int, short>(); + test<int*, char>(); +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp new file mode 100644 index 0000000000000..3756e963fa350 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// tuple_size<pair<T1, T2> >::value + +#include <utility> + +int main() +{ + { + typedef std::pair<int, short> P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> const P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> volatile P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> const volatile P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } +} diff --git a/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp b/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp new file mode 100644 index 0000000000000..90476bcde28c9 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// struct piecewise_construct_t { }; +// constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +#include <utility> +#include <tuple> +#include <cassert> + +class A +{ + int i_; + char c_; +public: + A(int i, char c) : i_(i), c_(c) {} + int get_i() const {return i_;} + char get_c() const {return c_;} +}; + +class B +{ + double d_; + unsigned u1_; + unsigned u2_; +public: + B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {} + double get_d() const {return d_;} + unsigned get_u1() const {return u1_;} + unsigned get_u2() const {return u2_;} +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::pair<A, B> p(std::piecewise_construct, + std::make_tuple(4, 'a'), + std::make_tuple(3.5, 6u, 2u)); + assert(p.first.get_i() == 4); + assert(p.first.get_c() == 'a'); + assert(p.second.get_d() == 3.5); + assert(p.second.get_u1() == 6u); + assert(p.second.get_u2() == 2u); +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp b/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp new file mode 100644 index 0000000000000..b58f5c55b643a --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp new file mode 100644 index 0000000000000..8c7dee2499ddc --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair(U&& x, V&& y); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<int>, short*> P; + P p(std::unique_ptr<int>(new int(3)), nullptr); + assert(*p.first == 3); + assert(p.second == nullptr); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp new file mode 100644 index 0000000000000..fdef5961437a5 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair& operator=(const pair<U, V>& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + P1 p1(3, 4); + P2 p2; + p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp new file mode 100644 index 0000000000000..a753ee520dfab --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair& operator=(pair&& p); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<int>, short> P; + P p1(std::unique_ptr<int>(new int(3)), 4); + P p2; + p2 = std::move(p1); + assert(*p2.first == 3); + assert(p2.second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp new file mode 100644 index 0000000000000..a200390f4882f --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair& operator=(pair<U, V>&& p); + +#include <utility> +#include <memory> +#include <cassert> + +struct Base +{ + virtual ~Base() {} +}; + +struct Derived + : public Base +{ +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<Derived>, short> P1; + typedef std::pair<std::unique_ptr<Base>, long> P2; + P1 p1(std::unique_ptr<Derived>(), 4); + P2 p2; + p2 = std::move(p1); + assert(p2.first == nullptr); + assert(p2.second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp new file mode 100644 index 0000000000000..2041b39c2dc91 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(const T1& x, const T2& y); + +#include <utility> +#include <cassert> + +class A +{ + int data_; +public: + A(int data) : data_(data) {} + + bool operator==(const A& a) const {return data_ == a.data_;} +}; + +#if _LIBCPP_STD_VER > 11 +class AC +{ + int data_; +public: + constexpr AC(int data) : data_(data) {} + + constexpr bool operator==(const AC& a) const {return data_ == a.data_;} +}; +#endif + +int main() +{ + { + typedef std::pair<float, short*> P; + P p(3.5f, 0); + assert(p.first == 3.5f); + assert(p.second == nullptr); + } + { + typedef std::pair<A, int> P; + P p(1, 2); + assert(p.first == A(1)); + assert(p.second == 2); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<float, short*> P; + constexpr P p(3.5f, 0); + static_assert(p.first == 3.5f, ""); + static_assert(p.second == nullptr, ""); + } + { + typedef std::pair<AC, int> P; + constexpr P p(1, 2); + static_assert(p.first == AC(1), ""); + static_assert(p.second == 2, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp new file mode 100644 index 0000000000000..286cce47f0503 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class U, class V> pair(const pair<U, V>& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + P1 p1(3, 4); + P2 p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + constexpr P1 p1(3, 4); + constexpr P2 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp new file mode 100644 index 0000000000000..4b54f717045ad --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(const pair&) = default; + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } + + static_assert((std::is_trivially_copy_constructible<std::pair<int, int> >::value), ""); + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + constexpr P1 p1(3, 4); + constexpr P1 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp new file mode 100644 index 0000000000000..bb6661f7966ce --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// constexpr pair(); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<float, short*> P; + P p; + assert(p.first == 0.0f); + assert(p.second == nullptr); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<float, short*> P; + constexpr P p; + static_assert(p.first == 0.0f, ""); + static_assert(p.second == nullptr, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp new file mode 100644 index 0000000000000..42a2666dd04b4 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class... Args1, class... Args2> +// pair(piecewise_construct_t, tuple<Args1...> first_args, +// tuple<Args2...> second_args); + +#include <utility> +#include <tuple> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + { + typedef std::pair<int, int*> P1; + typedef std::pair<int*, int> P2; + typedef std::pair<P1, P2> P3; + P3 p3(std::piecewise_construct, std::tuple<int, int*>(3, nullptr), + std::tuple<int*, int>(nullptr, 4)); + assert(p3.first == P1(3, nullptr)); + assert(p3.second == P2(nullptr, 4)); + } +#endif // _LIBCPP_HAS_NO_VARIADICS +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp new file mode 100644 index 0000000000000..5fb6c98979b5d --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class U, class V> pair(pair<U, V>&& p); + +#include <utility> +#include <memory> +#include <cassert> + +struct Base +{ + virtual ~Base() {} +}; + +struct Derived + : public Base +{ +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<Derived>, short> P1; + typedef std::pair<std::unique_ptr<Base>, long> P2; + P1 p1(std::unique_ptr<Derived>(), 4); + P2 p2 = std::move(p1); + assert(p2.first == nullptr); + assert(p2.second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp new file mode 100644 index 0000000000000..a912df00d7bb6 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// void swap(pair& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2(5, 6); + p1.swap(p2); + assert(p1.first == 5); + assert(p1.second == 6); + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp new file mode 100644 index 0000000000000..c16bd71ffcb23 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> +// struct pair +// { +// typedef T1 first_type; +// typedef T2 second_type; + +#include <utility> +#include <type_traits> + +int main() +{ + typedef std::pair<float, short*> P; + static_assert((std::is_same<P::first_type, float>::value), ""); + static_assert((std::is_same<P::second_type, short*>::value), ""); +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp new file mode 100644 index 0000000000000..9ba8532ab29ec --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(3, 4); + assert( (p1 == p2)); + assert(!(p1 != p2)); + assert(!(p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert( (p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(2, 4); + P p2(3, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert( (p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert(!(p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 2); + P p2(3, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert( (p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert(!(p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(2, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert(!(p1 < p2)); + assert(!(p1 <= p2)); + assert( (p1 > p2)); + assert( (p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(3, 2); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert(!(p1 < p2)); + assert(!(p1 <= p2)); + assert( (p1 > p2)); + assert( (p1 >= p2)); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P; + constexpr P p1(3, 4); + constexpr P p2(3, 2); + static_assert(!(p1 == p2), ""); + static_assert( (p1 != p2), ""); + static_assert(!(p1 < p2), ""); + static_assert(!(p1 <= p2), ""); + static_assert( (p1 > p2), ""); + static_assert( (p1 >= p2), ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp new file mode 100644 index 0000000000000..48e09735abb02 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1 = std::make_pair(3, 4); + assert(p1.first == 3); + assert(p1.second == 4); + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<int>, short> P1; + P1 p1 = std::make_pair(std::unique_ptr<int>(new int(3)), 4); + assert(*p1.first == 3); + assert(p1.second == 4); + } + { + typedef std::pair<std::unique_ptr<int>, short> P1; + P1 p1 = std::make_pair(nullptr, 4); + assert(p1.first == nullptr); + assert(p1.second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + constexpr P1 p1 = std::make_pair(3, 4); + static_assert(p1.first == 3, ""); + static_assert(p1.second == 4, ""); + } +#endif + +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..d9d8f27b5225c --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2(5, 6); + swap(p1, p2); + assert(p1.first == 5); + assert(p1.second == 6); + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/test/std/utilities/utility/utility.swap/swap.pass.cpp b/test/std/utilities/utility/utility.swap/swap.pass.cpp new file mode 100644 index 0000000000000..8606611f6603c --- /dev/null +++ b/test/std/utilities/utility/utility.swap/swap.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T> +// requires MoveAssignable<T> && MoveConstructible<T> +// void +// swap(T& a, T& b); + +#include <utility> +#include <cassert> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#include <memory> +#endif + +void +test() +{ + int i = 1; + int j = 2; + std::swap(i, j); + assert(i == 2); + assert(j == 1); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +void +test1() +{ + std::unique_ptr<int> i(new int(1)); + std::unique_ptr<int> j(new int(2)); + std::swap(i, j); + assert(*i == 2); + assert(*j == 1); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + test(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test1(); +#endif +} diff --git a/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp new file mode 100644 index 0000000000000..b1209c3c3651b --- /dev/null +++ b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<ValueType T, size_t N> +// requires Swappable<T> +// void +// swap(T (&a)[N], T (&b)[N]); + +#include <utility> +#include <cassert> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#include <memory> +#endif + +void +test() +{ + int i[3] = {1, 2, 3}; + int j[3] = {4, 5, 6}; + std::swap(i, j); + assert(i[0] == 4); + assert(i[1] == 5); + assert(i[2] == 6); + assert(j[0] == 1); + assert(j[1] == 2); + assert(j[2] == 3); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +void +test1() +{ + std::unique_ptr<int> i[3]; + for (int k = 0; k < 3; ++k) + i[k].reset(new int(k+1)); + std::unique_ptr<int> j[3]; + for (int k = 0; k < 3; ++k) + j[k].reset(new int(k+4)); + std::swap(i, j); + assert(*i[0] == 4); + assert(*i[1] == 5); + assert(*i[2] == 6); + assert(*j[0] == 1); + assert(*j[1] == 2); + assert(*j[2] == 3); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + test(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test1(); +#endif +} diff --git a/test/std/utilities/utility/version.pass.cpp b/test/std/utilities/utility/version.pass.cpp new file mode 100644 index 0000000000000..77d145d944574 --- /dev/null +++ b/test/std/utilities/utility/version.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +#include <utility> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |