diff options
Diffstat (limited to 'test/std/utilities/memory')
59 files changed, 712 insertions, 219 deletions
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 index 352c7c8d0caf..bbc6b470174d 100644 --- 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 @@ -21,6 +21,8 @@ #include <type_traits> #include <cassert> +#include "test_macros.h" + template <class T> struct A { @@ -61,7 +63,7 @@ int main() const B<int> b = {}; assert(std::allocator_traits<B<int> >::max_size(b) == 100); } -#if __cplusplus >= 201103 +#if TEST_STD_VER >= 11 { std::allocator<int> a; static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, ""); 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 index 20348d20c10c..10fbfe141ae5 100644 --- 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 @@ -20,6 +20,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct Ptr {}; @@ -47,9 +49,19 @@ struct C typedef CPtr<const T> const_pointer; }; +template <class T> +struct D { + typedef T value_type; +private: + typedef void 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<D<char> >::const_pointer, const char*>::value), ""); +#endif } 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 index 4b4045a51bae..8365d22613ee 100644 --- 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 @@ -21,6 +21,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct Ptr {}; @@ -47,9 +49,21 @@ struct C typedef CPtr<const void> const_void_pointer; }; + +template <class T> +struct D +{ + typedef T value_type; +private: + typedef int 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<D<char> >::const_void_pointer, const void*>::value), ""); +#endif } 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 index 085c911b0703..c728909477b5 100644 --- 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 @@ -20,6 +20,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -43,13 +45,24 @@ struct C struct const_void_pointer {}; }; + +template <class T> +struct D +{ + typedef T value_type; +private: + typedef void difference_type; +}; + namespace std { template <> struct pointer_traits<C<char>::pointer> { - typedef signed char difference_type; + typedef C<char>::pointer pointer; + typedef char element_type; + typedef signed char difference_type; }; } @@ -59,4 +72,7 @@ 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<D<char> >::difference_type, std::ptrdiff_t>::value), ""); +#endif } 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 index 60ba09499342..ff1ae2c051b6 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct Ptr {}; @@ -35,8 +37,18 @@ struct B typedef T value_type; }; +template <class T> +struct C { + typedef T value_type; +private: + typedef void pointer; +}; + 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<C<char> >::pointer, char*>::value), ""); +#endif } 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 index 604e890efaae..0112ab371a83 100644 --- 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 @@ -20,6 +20,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -33,8 +35,20 @@ struct B typedef T value_type; }; + +template <class T> +struct C +{ + typedef T value_type; +private: + typedef std::true_type propagate_on_container_copy_assignment; +}; + 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<C<char> >::propagate_on_container_copy_assignment, std::false_type>::value), ""); +#endif } 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 index 1d2b18686d0f..64de15c2cd48 100644 --- 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 @@ -20,6 +20,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -33,8 +35,21 @@ struct B typedef T value_type; }; + +template <class T> +struct C +{ + typedef T value_type; +private: + typedef std::true_type propagate_on_container_move_assignment; +}; + + 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<C<char> >::propagate_on_container_move_assignment, std::false_type>::value), ""); +#endif } 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 index 6730d1ae261a..a62336fa6cb0 100644 --- 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 @@ -20,6 +20,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -33,8 +35,19 @@ struct B typedef T value_type; }; +template <class T> +struct C +{ + typedef T value_type; +private: + typedef std::true_type propagate_on_container_swap; +}; + 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), ""); + #if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<C<char> >::propagate_on_container_swap, std::false_type>::value), ""); +#endif } 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 index 50611b99da9a..8097a66fc9d6 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct ReboundA {}; @@ -61,19 +63,39 @@ struct E template <class U> struct rebind {typedef ReboundA<U> otter;}; }; +template <class T> +struct F { + typedef T value_type; +private: + template <class> + struct rebind { typedef void other; }; +}; + +template <class T> +struct G { + typedef T value_type; + template <class> + struct rebind { + private: + typedef void other; + }; +}; + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 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<F<char> >::rebind_alloc<double>, F<double> >::value), ""); + static_assert((std::is_same<std::allocator_traits<G<char> >::rebind_alloc<double>, G<double> >::value), ""); +#else 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 +#endif } 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 index e9c175fe86a5..00ed50727c98 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -42,6 +44,14 @@ struct C struct const_void_pointer {}; }; +template <class T> +struct D { + typedef T value_type; + typedef short difference_type; +private: + typedef void size_type; +}; + namespace std { @@ -60,4 +70,7 @@ int main() std::make_unsigned<std::ptrdiff_t>::type>::value), ""); static_assert((std::is_same<std::allocator_traits<C<char> >::size_type, unsigned char>::value), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<D<char> >::size_type, unsigned short>::value), ""); +#endif } 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 index 74cd3475f664..2c3623793db6 100644 --- 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 @@ -20,6 +20,7 @@ #include <memory> #include <type_traits> +#include "test_macros.h" template <class T> struct Ptr {}; @@ -47,9 +48,21 @@ struct C typedef CPtr<void> void_pointer; }; + +template <class T> +struct D +{ + typedef T value_type; +private: + typedef 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), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::allocator_traits<D<char> >::void_pointer, void*>::value), ""); +#endif } 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 index 0477d9912e6e..bd32bc34e7a0 100644 --- 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 @@ -14,6 +14,8 @@ #include <memory> #include <vector> +#include "test_macros.h" + struct A { }; @@ -23,6 +25,19 @@ struct B typedef int allocator_type; }; +struct C { + static int allocator_type; +}; + +struct D { + static int allocator_type() { return 0; } +}; + +struct E { +private: + typedef int allocator_type; +}; + int main() { static_assert((!std::uses_allocator<int, std::allocator<int> >::value), ""); @@ -30,4 +45,9 @@ int main() 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), ""); + static_assert((!std::uses_allocator<C, decltype(C::allocator_type)>::value), ""); + static_assert((!std::uses_allocator<D, decltype(D::allocator_type)>::value), ""); +#if TEST_STD_VER >= 11 + static_assert((!std::uses_allocator<E, int>::value), ""); +#endif } diff --git a/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp new file mode 100644 index 000000000000..dc0bdd047c61 --- /dev/null +++ b/test/std/utilities/memory/default.allocator/allocator.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. +// +//===----------------------------------------------------------------------===// + +// XFAIL: libcpp-no-exceptions +// <memory> + +// allocator: +// pointer allocate(size_type n, allocator<void>::const_pointer hint=0); + +#include <memory> +#include <cassert> + +template <typename T> +void test_max(size_t count) +{ + std::allocator<T> a; + try { + a.allocate(count); + assert(false); + } catch (const std::exception &) { + } +} + +int main() +{ + { // Bug 26812 -- allocating too large + typedef double T; + std::allocator<T> a; + test_max<T> (a.max_size() + 1); // just barely too large + test_max<T> (a.max_size() * 2); // significantly too large + test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow + test_max<T> ((size_t) -1); // way too large + } + + { + typedef const double T; + std::allocator<T> a; + test_max<T> (a.max_size() + 1); // just barely too large + test_max<T> (a.max_size() * 2); // significantly too large + test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow + test_max<T> ((size_t) -1); // way too large + } +} diff --git a/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp b/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp index 5a8f7a28a042..e1612ae05421 100644 --- a/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp +++ b/test/std/utilities/memory/default.allocator/allocator_pointers.pass.cpp @@ -10,7 +10,9 @@ #include <memory> #include <cassert> -#if __cplusplus >= 201103L +#include "test_macros.h" + +#if TEST_STD_VER >= 11 // #include <memory> // // template <class Alloc> @@ -19,7 +21,7 @@ // 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> @@ -36,7 +38,10 @@ void test_pointer() { typename std::allocator_traits<Alloc>::pointer vp; typename std::allocator_traits<Alloc>::const_pointer cvp; - + + ((void)vp); // Prevent unused warning + ((void)cvp); // Prevent unused warning + 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, ""); @@ -70,7 +75,10 @@ void test_void_pointer() { typename std::allocator_traits<Alloc>::void_pointer vp; typename std::allocator_traits<Alloc>::const_void_pointer cvp; - + + ((void)vp); // Prevent unused warning + ((void)cvp); // Prevent unused warning + 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, ""); @@ -105,11 +113,11 @@ int main() { test_pointer<std::allocator<char>> (); test_pointer<std::allocator<int>> (); - test_pointer<std::allocator<Foo>> (); + test_pointer<std::allocator<Foo>> (); test_void_pointer<std::allocator<char>> (); test_void_pointer<std::allocator<int>> (); - test_void_pointer<std::allocator<Foo>> (); + test_void_pointer<std::allocator<Foo>> (); } #else int main() {} 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 index 4efe61342420..27b2d08b0061 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + struct A { typedef short element_type; @@ -39,10 +41,26 @@ struct D typedef char difference_type; }; +template <class T> +struct E +{ + static int difference_type; +}; + +template <class T> +struct F { +private: + typedef int 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), ""); + static_assert((std::is_same<std::pointer_traits<E<int> >::difference_type, std::ptrdiff_t>::value), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::pointer_traits<F<int>>::difference_type, std::ptrdiff_t>::value), ""); +#endif } 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 index 0ee1e8c93a67..48399d5355d6 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + struct A { typedef char element_type; @@ -40,10 +42,27 @@ struct D { }; +template <class T, class U> +struct E +{ + static int element_type; +}; + +template <class T> +struct F { +private: + typedef int element_type; +}; + 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), ""); + static_assert((std::is_same<std::pointer_traits<E<double, int> >::element_type, double>::value), ""); +#if TEST_STD_VER >= 11 + static_assert((std::is_same<std::pointer_traits<F<double>>::element_type, double>::value), ""); +#endif + } 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 index 4a1455c53ef6..74c124901211 100644 --- 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 @@ -19,6 +19,8 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + template <class T> struct A { @@ -29,7 +31,7 @@ template <class T> struct B1 {}; template <class T> struct B { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 template <class U> using rebind = B1<U>; #else template <class U> struct rebind {typedef B1<U> other;}; @@ -46,24 +48,58 @@ template <class T, class U> struct D1 {}; template <class T, class U> struct D { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 template <class V> using rebind = D1<V, U>; #else template <class V> struct rebind {typedef D1<V, U> other;}; #endif }; +template <class T, class U> +struct E +{ + template <class> + void rebind() {} +}; + + +#if TEST_STD_VER >= 11 +template <class T, class U> +struct F { +private: + template <class> + using rebind = void; +}; +#endif + +#if TEST_STD_VER >= 14 +template <class T, class U> +struct G +{ + template <class> + static constexpr int rebind = 42; +}; +#endif + + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 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<E<char, int> >::rebind<double>, E<double, int> >::value), ""); + static_assert((std::is_same<std::pointer_traits<F<char, int> >::rebind<double>, F<double, int> >::value), ""); + +#if TEST_STD_VER >= 14 + static_assert((std::is_same<std::pointer_traits<G<char, int> >::rebind<double>, G<double, int> >::value), ""); +#endif +#else // TEST_STD_VER < 11 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 + static_assert((std::is_same<std::pointer_traits<E<char, int> >::rebind<double>::other, E<double, int> >::value), ""); +#endif } diff --git a/test/std/utilities/memory/specialized.algorithms/specialized.addressof/constexpr_addressof.pass.cpp b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/constexpr_addressof.pass.cpp new file mode 100644 index 000000000000..a371f8eda1a8 --- /dev/null +++ b/test/std/utilities/memory/specialized.algorithms/specialized.addressof/constexpr_addressof.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// XFAIL: gcc + +// <memory> + +// template <ObjectType T> constexpr T* addressof(T& r); + +#include <memory> +#include <cassert> + +struct Pointer { + constexpr Pointer(void* v) : value(v) {} + void* value; +}; + +struct A +{ + constexpr A() : n(42) {} + void operator&() const { } + int n; +}; + +constexpr int i = 0; +constexpr double d = 0.0; +constexpr A a{}; + +int main() +{ + static_assert(std::addressof(i) == &i, ""); + static_assert(std::addressof(d) == &d, ""); + constexpr const A* ap = std::addressof(a); + static_assert(&ap->n == &a.n, ""); +} 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 index 8bb818319a37..1debd6d75ff0 100644 --- 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 @@ -36,7 +36,7 @@ struct Nasty Nasty() : i_ ( counter_++ ) {} Nasty * operator &() const { return NULL; } int i_; - static int counter_; + static int counter_; }; int Nasty::counter_ = 0; @@ -76,5 +76,5 @@ int main() 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 index ae438ef7d561..83aa19471ada 100644 --- 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 @@ -36,7 +36,7 @@ struct Nasty Nasty() : i_ ( counter_++ ) {} Nasty * operator &() const { return NULL; } int i_; - static int counter_; + static int counter_; }; int Nasty::counter_ = 0; 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 index 22aa8b98b8c9..5f90a3792064 100644 --- 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 @@ -35,7 +35,7 @@ struct Nasty Nasty() : i_ ( counter_++ ) {} Nasty * operator &() const { return NULL; } int i_; - static int counter_; + static int counter_; }; int Nasty::counter_ = 0; 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 index 95c45dd50541..3816a2528688 100644 --- 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 @@ -36,7 +36,7 @@ struct Nasty Nasty() : i_ ( counter_++ ) {} Nasty * operator &() const { return NULL; } int i_; - static int counter_; + static int counter_; }; int Nasty::counter_ = 0; diff --git a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp b/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp index 27b620569b83..62a3be80d8b6 100644 --- a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp +++ b/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp @@ -13,6 +13,8 @@ #include <type_traits> #include <cassert> +#include "test_macros.h" + int A_constructed = 0; struct A @@ -29,7 +31,7 @@ public: int main() { -#if __cplusplus >= 201402L +#if TEST_STD_VER >= 14 typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type Storage; Storage buffer; diff --git a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp b/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp index 914802423ce7..914802423ce7 100644 --- a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp +++ b/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp 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 index b2fb58f529f3..30b4ecb94e18 100644 --- 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 @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 #include <memory> #include <string> #include <cassert> @@ -23,23 +24,21 @@ private: 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.array4.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp index 26eb59bbfd71..07aa659bd9b0 100644 --- 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 @@ -13,5 +13,5 @@ int main() { - auto up4 = std::make_unique<int[5]>(11, 22, 33, 44, 55); // deleted + 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 index 7326ed226557..ace2e4fc7137 100644 --- 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 @@ -7,20 +7,20 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 #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!" ); @@ -29,5 +29,4 @@ int main() p2 = std::make_unique<std::string> ( 6, 'z' ); assert ( *p2 == "zzzzzz" ); } -#endif // _LIBCPP_STD_VER > 11 } diff --git a/test/std/utilities/memory/version.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp index 790c08a3bd2d..a611b1a12f05 100644 --- a/test/std/utilities/memory/version.pass.cpp +++ b/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp @@ -9,12 +9,19 @@ // <memory> -#include <memory> +// default_delete[] + +// template <class U> +// default_delete(const default_delete<U[]>&); +// +// This constructor shall not participate in overload resolution unless +// U(*)[] is convertible to T(*)[]. -#ifndef _LIBCPP_VERSION -#error _LIBCPP_VERSION not defined -#endif +#include <memory> +#include <cassert> int main() { + std::default_delete<int[]> d1; + std::default_delete<const int[]> d2 = d1; } 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 index 2d62bccdce50..2b0b5f0d945d 100644 --- 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 @@ -40,4 +40,10 @@ int main() assert(s.get_deleter().state() == 0); } assert(A::count == 0); + + { // LWG#2520 says that nullptr is a valid input as well as null + std::unique_ptr<A[], Deleter<A[]> > s1(NULL, Deleter<A[]>()); + std::unique_ptr<A[], Deleter<A[]> > s2(nullptr, Deleter<A[]>()); + } + 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 index 914076b50f42..a92fdbc1d2c4 100644 --- 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 @@ -55,4 +55,10 @@ int main() assert(s.get_deleter().state() == 5); } assert(A::count == 0); + { + Deleter d; + std::unique_ptr<A[], Deleter> s(nullptr, d); + assert(s.get() == nullptr); + assert(s.get_deleter().state() == 5); + } } 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 index a6f535f38f08..dd27401731a6 100644 --- 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 @@ -57,4 +57,9 @@ int main() assert(s.get_deleter().state() == 6); } assert(A::count == 0); + { + Deleter d; + std::unique_ptr<A[], Deleter&> s(nullptr, d); + assert(s.get() == nullptr); + } } 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 index a4c917c1af76..02f44d357561 100644 --- 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 @@ -55,4 +55,9 @@ int main() assert(s.get_deleter().state() == 5); } assert(A::count == 0); + { + Deleter d; + std::unique_ptr<A[], const Deleter&> s(nullptr, d); + assert(s.get() == nullptr); + } } 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 index 8721062c6d02..380f2e100eb6 100644 --- 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 @@ -16,11 +16,22 @@ #include <memory> #include <type_traits> +#include "test_macros.h" + struct Deleter { struct pointer {}; }; +struct D2 { +private: + typedef void pointer; +}; + +struct D3 { + static long pointer; +}; + int main() { { @@ -31,4 +42,14 @@ int main() typedef std::unique_ptr<int, Deleter> P; static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); } +#if TEST_STD_VER >= 11 + { + typedef std::unique_ptr<int, D2> P; + static_assert(std::is_same<P::pointer, int*>::value, ""); + } + { + typedef std::unique_ptr<int, D3> P; + static_assert(std::is_same<P::pointer, int*>::value, ""); + } +#endif } 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 index 44b746fbcfd8..c525137d4841 100644 --- 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 @@ -16,6 +16,7 @@ #include <memory> #include <cassert> +#include "test_macros.h" #include "../deleter.h" struct A @@ -34,6 +35,16 @@ struct A int A::count = 0; +template <class T> +struct NonSwappableDeleter { + explicit NonSwappableDeleter(int) {} + NonSwappableDeleter& operator=(NonSwappableDeleter const&) { return *this; } + void operator()(T*) const {} +private: + NonSwappableDeleter(NonSwappableDeleter const&); + +}; + int main() { { @@ -74,4 +85,18 @@ int main() assert(A::count == 6); } assert(A::count == 0); +#if TEST_STD_VER >= 11 + { + // test that unique_ptr's specialized swap is disabled when the deleter + // is non-swappable. Instead we should pick up the generic swap(T, T) + // and perform 3 move constructions. + typedef NonSwappableDeleter<int> D; + D d(42); + int x = 42; + int y = 43; + std::unique_ptr<int, D&> p(&x, d); + std::unique_ptr<int, D&> p2(&y, d); + std::swap(p, p2); + } +#endif } 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 index 77af13fa90d1..b9f8ee0746c3 100644 --- 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 @@ -18,11 +18,16 @@ // public: // shared_ptr<T> shared_from_this(); // shared_ptr<T const> shared_from_this() const; +// weak_ptr<T> weak_from_this() noexcept; // C++17 +// weak_ptr<T const> weak_from_this() const noexecpt; // C++17 // }; #include <memory> #include <cassert> +#include "test_macros.h" +#include "count_new.hpp" + struct T : public std::enable_shared_from_this<T> { @@ -32,12 +37,31 @@ struct Y : T {}; struct Z : Y {}; +void nullDeleter(void*) {} + +struct Foo : virtual public std::enable_shared_from_this<Foo> +{ + virtual ~Foo() {} +}; + +struct Bar : public Foo { + Bar(int) {} +}; + + 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>()); } + { // https://llvm.org/bugs/show_bug.cgi?id=27115 + int x = 42; + std::shared_ptr<Bar> t1(new Bar(42)); + assert(t1->shared_from_this() == t1); + std::shared_ptr<Bar> t2(std::make_shared<Bar>(x)); + assert(t2->shared_from_this() == t2); + } { std::shared_ptr<Y> p(new Z); std::shared_ptr<T> q = p->shared_from_this(); @@ -50,4 +74,89 @@ int main() assert(p == q); assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership } + // Test LWG issue 2529. Only reset '__weak_ptr_' when it's already expired. + // http://cplusplus.github.io/LWG/lwg-active.html#2529. + // Test two different ways: + // * Using 'weak_from_this().expired()' in C++17. + // * Using 'shared_from_this()' in all dialects. + { + assert(globalMemCounter.checkOutstandingNewEq(0)); + T* ptr = new T; + std::shared_ptr<T> s(ptr); + { + // Don't re-initialize the "enabled_shared_from_this" base + // because it already references a non-expired shared_ptr. + std::shared_ptr<T> s2(ptr, &nullDeleter); + } +#if TEST_STD_VER > 14 + // The enabled_shared_from_this base should still be referencing + // the original shared_ptr. + assert(!ptr->weak_from_this().expired()); +#endif +#ifndef TEST_HAS_NO_EXCEPTIONS + { + try { + std::shared_ptr<T> new_s = ptr->shared_from_this(); + assert(new_s == s); + } catch (std::bad_weak_ptr const&) { + assert(false); + } catch (...) { + assert(false); + } + } +#endif + s.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); + } + // Test LWG issue 2529 again. This time check that an expired pointer + // is replaced. + { + assert(globalMemCounter.checkOutstandingNewEq(0)); + T* ptr = new T; + std::weak_ptr<T> weak; + { + std::shared_ptr<T> s(ptr, &nullDeleter); + assert(ptr->shared_from_this() == s); + weak = s; + assert(!weak.expired()); + } + assert(weak.expired()); + weak.reset(); + +#ifndef TEST_HAS_NO_EXCEPTIONS + try { + ptr->shared_from_this(); + assert(false); + } catch (std::bad_weak_ptr const&) { + } catch (...) { assert(false); } +#endif + { + std::shared_ptr<T> s2(ptr, &nullDeleter); + assert(ptr->shared_from_this() == s2); + } + delete ptr; + assert(globalMemCounter.checkOutstandingNewEq(0)); + } + // Test weak_from_this_methods +#if TEST_STD_VER > 14 + { + T* ptr = new T; + const T* cptr = ptr; + + static_assert(noexcept(ptr->weak_from_this()), "Operation must be noexcept"); + static_assert(noexcept(cptr->weak_from_this()), "Operation must be noexcept"); + + std::weak_ptr<T> my_weak = ptr->weak_from_this(); + assert(my_weak.expired()); + + std::weak_ptr<T const> my_const_weak = cptr->weak_from_this(); + assert(my_const_weak.expired()); + + // Enable shared_from_this with ptr. + std::shared_ptr<T> sptr(ptr); + my_weak = ptr->weak_from_this(); + assert(!my_weak.expired()); + assert(my_weak.lock().get() == ptr); + } +#endif } 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 index 2d586e9c7fdd..3bad537e3431 100644 --- 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 @@ -23,12 +23,15 @@ // atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v, // shared_ptr<T> w); +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> v(new int(3)); @@ -49,5 +52,4 @@ int main() 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 index 34da04cc1810..5cc1234ad34e 100644 --- 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 @@ -24,12 +24,15 @@ // shared_ptr<T> w, memory_order success, // memory_order failure); +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> v(new int(3)); @@ -54,5 +57,4 @@ int main() 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 index 50b96e551fd3..a89c0dbd2207 100644 --- 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 @@ -23,12 +23,15 @@ // atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, // shared_ptr<T> w); +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> v(new int(3)); @@ -49,5 +52,4 @@ int main() 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 index d304319d251d..821cea6868e4 100644 --- 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 @@ -24,12 +24,15 @@ // shared_ptr<T> w, memory_order success, // memory_order failure); +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> v(new int(3)); @@ -54,5 +57,4 @@ int main() 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 index 3b44c8ba9b33..66be756d54fd 100644 --- 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 @@ -22,12 +22,15 @@ // shared_ptr<T> // atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> r(new int(3)); @@ -35,5 +38,4 @@ int main() 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 index 598a1b8da175..493ba7fcc94d 100644 --- 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 @@ -22,12 +22,15 @@ // shared_ptr<T> // atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + int main() { -#if __has_feature(cxx_atomic) { std::shared_ptr<int> p(new int(4)); std::shared_ptr<int> r(new int(3)); @@ -35,5 +38,4 @@ int main() 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 index e3ac84a4fa50..f72a0bb24285 100644 --- 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 @@ -17,15 +17,17 @@ // bool // atomic_is_lock_free(const shared_ptr<T>* p); +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + 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 index d4a39c878ac7..4820d05420a2 100644 --- 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 @@ -22,16 +22,18 @@ // shared_ptr<T> // atomic_load(const shared_ptr<T>* p) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + 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 index af11dc8bc2c9..ef8dc822102f 100644 --- 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 @@ -22,16 +22,18 @@ // shared_ptr<T> // atomic_load_explicit(const shared_ptr<T>* p, memory_order mo) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + 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 index 7a85a9934ef0..a13a7d57ab96 100644 --- 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 @@ -22,17 +22,19 @@ // void // atomic_store(shared_ptr<T>* p, shared_ptr<T> r) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + 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 index c81266c55fa4..6dfe3166c8c5 100644 --- 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 @@ -22,17 +22,19 @@ // void // atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo) +// UNSUPPORTED: c++98, c++03 + #include <memory> #include <cassert> +#include "test_macros.h" + 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 index 0263061b3a84..bae1e013f571 100644 --- 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 @@ -52,7 +52,7 @@ public: void set_state(int i) {state_ = i;} void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;} - + test_deleter* operator&() const DELETE_FUNCTION; }; 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 index 8175312334f6..f44c05eb7c86 100644 --- 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 @@ -13,14 +13,20 @@ // { // public: // typedef T element_type; +// typedef weak_ptr<T> weak_type; // C++17 // ... // }; #include <memory> +#include "test_macros.h" + struct A; // purposefully incomplete int main() { static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), ""); +#if TEST_STD_VER > 14 + static_assert((std::is_same<std::shared_ptr<A>::weak_type, std::weak_ptr<A>>::value), ""); +#endif } 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 index f17485108b92..f8fdb7a09478 100644 --- 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 @@ -7,31 +7,18 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // <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); -} +#include "test_macros.h" +#include "count_new.hpp" struct B { @@ -59,47 +46,51 @@ 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::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); +#if TEST_STD_VER >= 11 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); + assert(p.use_count() == 1); + assert(p.get() == raw_ptr); + assert(ptr.get() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); +#if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT) + { + std::auto_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + globalMemCounter.throw_after = 0; + try + { +#if TEST_STD_VER >= 11 + std::shared_ptr<B> p(std::move(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); + std::shared_ptr<B> p(ptr); #endif - } + assert(false); + } + catch (...) + { +#if TEST_STD_VER >= 11 + 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); + assert(globalMemCounter.checkOutstandingNewEq(0)); +#endif // !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT) } 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 index b67f31ee45a8..8a6cd0f352ff 100644 --- 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 @@ -65,7 +65,7 @@ int main() assert(test_deleter<A>::count == 0); assert(test_deleter<A>::dealloc_count == 1); test_deleter<A>::dealloc_count = 0; -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 // Test an allocator that returns class-type pointers { std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>()); 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 index 6a79a8ef60db..85fc5e930544 100644 --- 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 @@ -8,18 +8,22 @@ //===----------------------------------------------------------------------===// // XFAIL: libcpp-no-exceptions +// UNSUPPORTED: sanitizer-new-delete + // <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_macros.h" +#include "count_new.hpp" + #include "../test_deleter.h" struct A @@ -33,23 +37,10 @@ struct A 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; + globalMemCounter.throw_after = 0; try { std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); 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 index 1a9c09cdb78c..b0facfc1a6eb 100644 --- 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 @@ -68,7 +68,7 @@ int main() assert(test_deleter<A>::count == 0); assert(test_deleter<A>::dealloc_count == 1); test_deleter<A>::dealloc_count = 0; -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 // Test an allocator that returns class-type pointers { A* ptr = new A; 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 index 982313b07499..70af2964113d 100644 --- 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 @@ -8,18 +8,20 @@ //===----------------------------------------------------------------------===// // XFAIL: libcpp-no-exceptions +// UNSUPPORTED: sanitizer-new-delete + // <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 "count_new.hpp" #include "../test_deleter.h" struct A @@ -33,24 +35,10 @@ struct A 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; + globalMemCounter.throw_after = 0; try { std::shared_ptr<A> p(ptr, test_deleter<A>(3)); @@ -62,4 +50,5 @@ int main() assert(test_deleter<A>::count == 0); assert(test_deleter<A>::dealloc_count == 1); } + assert(globalMemCounter.checkOutstandingNewEq(0)); } 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 index 2e761d70bba0..2fa975eca833 100644 --- 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 @@ -8,17 +8,20 @@ //===----------------------------------------------------------------------===// // XFAIL: libcpp-no-exceptions +// UNSUPPORTED: sanitizer-new-delete + // <memory> // template<class Y> explicit shared_ptr(Y* p); -// UNSUPPORTED: sanitizer-new-delete #include <memory> #include <new> #include <cstdlib> #include <cassert> +#include "count_new.hpp" + struct A { static int count; @@ -30,26 +33,12 @@ struct A 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); + globalMemCounter.throw_after = 0; try { std::shared_ptr<A> p(ptr); @@ -59,5 +48,5 @@ int main() { assert(A::count == 0); } - } + assert(globalMemCounter.checkOutstandingNewEq(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 index c62fcd689320..5c424f5c7428 100644 --- 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 @@ -8,30 +8,19 @@ //===----------------------------------------------------------------------===// // XFAIL: libcpp-no-exceptions +// UNSUPPORTED: sanitizer-new-delete + // <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); -} +#include "test_macros.h" +#include "count_new.hpp" struct B { @@ -65,52 +54,46 @@ 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::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); 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(p.use_count() == 1); + assert(p.get() == raw_ptr); assert(ptr.get() == 0); -#endif - } } assert(A::count == 0); - - // LWG 2399 { - throw_next = false; - fn(std::unique_ptr<int>(new int)); + std::unique_ptr<A> ptr(new A); + A* raw_ptr = ptr.get(); + globalMemCounter.throw_after = 0; + try + { + std::shared_ptr<B> p(std::move(ptr)); + assert(false); + } + catch (...) + { +#if TEST_STD_VER >= 11 + 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 + } } - -#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 + assert(A::count == 0); + { // LWG 2399 + fn(std::unique_ptr<int>(new int)); + } +#if TEST_STD_VER >= 14 + { // 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.create/allocate_shared.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index aa77dab51515..3e4a99e981d4 100644 --- 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 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // <memory> // shared_ptr @@ -55,7 +57,6 @@ int main() } assert(A::count == 0); assert(test_allocator<A>::alloc_count == 0); -#if __cplusplus >= 201103L { int i = 67; char c = 'e'; @@ -74,5 +75,4 @@ int main() 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_cxx03.pass.cpp index 8dcd50e49411..527bbce1473e 100644 --- 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_cxx03.pass.cpp @@ -14,7 +14,7 @@ // 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> @@ -112,7 +112,7 @@ int main() assert(test_allocator<Two>::alloc_count == 0); test<bare_allocator<void> >(); -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 test<min_allocator<void> >(); #endif } 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 index 1045f9347b38..59cd3d248639 100644 --- 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 @@ -34,7 +34,7 @@ void test(const T &t0) assert(*p0 == t0); assert(*p1 == t1); } - + { volatile T t1 = t0; std::shared_ptr<volatile T> p0 = std::make_shared<volatile T>(t0); @@ -50,7 +50,7 @@ void test(const T &t0) assert(*p0 == t0); assert(*p1 == t1); } - + } int main() 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 index bf1719c66ffa..142eba2d9647 100644 --- 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 @@ -30,7 +30,7 @@ // bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; // bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; // }; -// +// // Added in C++17 // template<> struct owner_less<void> // { @@ -42,7 +42,7 @@ // bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const; // template<class T, class U> // bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const; -// +// // typedef unspecified is_transparent; // }; @@ -113,7 +113,7 @@ int main() cmp(wp1, wp1); } { - // test heterogeneous lookups + // test heterogeneous lookups std::set<std::shared_ptr<X>, std::owner_less<>> s; std::shared_ptr<void> vp; s.find(vp); |
