diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-12-14 21:29:29 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-12-14 21:29:29 +0000 |
commit | 4ffd08cae91e6bfbf1519420aeb096964d27fd39 (patch) | |
tree | 14d8bd3bb9ab233e6ed25243c132f2ada96a8c59 /libcxx/test/std/utilities/allocator.adaptor | |
parent | fec6be9c8150244c98bc2ac2bcac326fce49001a (diff) | |
download | bcm5719-llvm-4ffd08cae91e6bfbf1519420aeb096964d27fd39.tar.gz bcm5719-llvm-4ffd08cae91e6bfbf1519420aeb096964d27fd39.zip |
[libcxx] Fix PR24075, PR23841 - Add scoped_allocator_adaptor::construct(pair<T, U>*, ...) overloads.
Summary:
For more information see:
* https://llvm.org/bugs/show_bug.cgi?id=23841
* https://llvm.org/bugs/show_bug.cgi?id=24075
I hope you have as much fun reviewing as I did writing these insane tests!
Reviewers: mclow.lists, AlisdairM, EricWF
Subscribers: AlisdairM, Potatoswatter, cfe-commits
Differential Revision: https://reviews.llvm.org/D27612
llvm-svn: 289710
Diffstat (limited to 'libcxx/test/std/utilities/allocator.adaptor')
6 files changed, 891 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp new file mode 100644 index 00000000000..4e73d806431 --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// The 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 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class U1, class U2> +// void scoped_allocator_adaptor::construct(pair<U1, U2>*) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + + +void test_no_inner_alloc() +{ + using VoidAlloc = CountingAllocator<void>; + AllocController P; + { + using T = UsesAllocatorV1<VoidAlloc, 0>; + using U = UsesAllocatorV2<VoidAlloc, 0>; + using Pair = std::pair<T, U>; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr); + assert(checkConstruct<>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<>(ptr->second, UA_AllocLast, CA)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&>&&, + std::tuple<SA&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + + } + P.reset(); + { + using T = UsesAllocatorV3<VoidAlloc, 0>; + using U = NotUsesAllocator<VoidAlloc, 0>; + using Pair = std::pair<T, U>; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr); + assert(checkConstruct<>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<>(ptr->second, UA_None)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&>&&, + std::tuple<>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} + +void test_with_inner_alloc() +{ + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 0>; + using U = UsesAllocatorV2<VoidAlloc2, 0>; + using Pair = std::pair<T, U>; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr); + assert(checkConstruct<>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<>(ptr->second, UA_AllocLast)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&>&&, + std::tuple<SAInner&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } + PInner.reset(); + POuter.reset(); + { + using T = UsesAllocatorV3<VoidAlloc2, 0>; + using U = NotUsesAllocator<VoidAlloc2, 0>; + using Pair = std::pair<T, U>; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr); + assert(checkConstruct<>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<>(ptr->second, UA_None)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&>&&, + std::tuple<>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} +int main() { + test_no_inner_alloc(); + test_with_inner_alloc(); +} diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp new file mode 100644 index 00000000000..9effb6eded3 --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class U1, class U2> +// void scoped_allocator_adaptor::construct(pair<U1, U2>*, pair<T1, T2>const&) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + + +void test_no_inner_alloc() +{ + using VoidAlloc = CountingAllocator<void>; + AllocController P; + { + using T = UsesAllocatorV1<VoidAlloc, 1>; + using U = UsesAllocatorV2<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int&, int const&&>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + const PairIn in(x, std::move(y)); + A.construct(ptr, in); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&>(ptr->second, UA_AllocLast, CA)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&>&&, + std::tuple<int const&, SA&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + + } + P.reset(); + { + using T = UsesAllocatorV3<VoidAlloc, 1>; + using U = NotUsesAllocator<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int, int const&>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + const PairIn in(x, y); + A.construct(ptr, in); + assert(checkConstruct<int const&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int const&>&&, + std::tuple<int const&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} + +void test_with_inner_alloc() +{ + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 1>; + using U = UsesAllocatorV2<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int&, int const&&>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + const PairIn in(x, std::move(y)); + A.construct(ptr, in); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&>(ptr->second, UA_AllocLast)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&>&&, + std::tuple<int const&, SAInner&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } + PInner.reset(); + POuter.reset(); + { + using T = UsesAllocatorV3<VoidAlloc2, 1>; + using U = NotUsesAllocator<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int, int const &>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + const PairIn in(x, y); + A.construct(ptr, in); + assert(checkConstruct<int const&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int const&>&&, + std::tuple<int const&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} +int main() { + test_no_inner_alloc(); + test_with_inner_alloc(); +} diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp new file mode 100644 index 00000000000..4d371f206e6 --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class U1, class U2, class ...Args1, class ...Args2> +// void scoped_allocator_adaptor::construct(pair<U1, U2>*, +// piecewise_construct_t, tuple<Args1...>, tuple<Args2...>) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + + +void test_no_inner_alloc() +{ + using VoidAlloc = CountingAllocator<void>; + AllocController P; + { + using T = UsesAllocatorV1<VoidAlloc, 1>; + using U = UsesAllocatorV2<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr, std::piecewise_construct, + std::forward_as_tuple(x), + std::forward_as_tuple(std::move(y))); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast, CA)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&>&&, + std::tuple<int const&&, SA&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + + } + P.reset(); + { + using T = UsesAllocatorV3<VoidAlloc, 1>; + using U = NotUsesAllocator<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr, std::piecewise_construct, + std::forward_as_tuple(std::move(x)), + std::forward_as_tuple(y)); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&&>&&, + std::tuple<int const&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} + +void test_with_inner_alloc() +{ + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 1>; + using U = UsesAllocatorV2<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr, std::piecewise_construct, + std::forward_as_tuple(x), + std::forward_as_tuple(std::move(y))); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int &&>(ptr->second, UA_AllocLast)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&>&&, + std::tuple<int &&, SAInner&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } + PInner.reset(); + POuter.reset(); + { + using T = UsesAllocatorV3<VoidAlloc2, 1>; + using U = NotUsesAllocator<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr, std::piecewise_construct, + std::forward_as_tuple(std::move(x)), + std::forward_as_tuple(std::move(y))); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&&>(ptr->second, UA_None)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&&>&&, + std::tuple<int const&&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} +int main() { + test_no_inner_alloc(); + test_with_inner_alloc(); +} diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp new file mode 100644 index 00000000000..1d0fb5157c0 --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class U1, class U2> +// void scoped_allocator_adaptor::construct(pair<U1, U2>*, pair<T1, T2>&&) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + + +void test_no_inner_alloc() +{ + using VoidAlloc = CountingAllocator<void>; + AllocController P; + { + using T = UsesAllocatorV1<VoidAlloc, 1>; + using U = UsesAllocatorV2<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int&, int const&&>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + PairIn in(x, std::move(y)); + A.construct(ptr, std::move(in)); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast, CA)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&>&&, + std::tuple<int const&&, SA&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + + } + P.reset(); + { + using T = UsesAllocatorV3<VoidAlloc, 1>; + using U = NotUsesAllocator<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int, int const&>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + PairIn in(x, y); + A.construct(ptr, std::move(in)); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&&>&&, + std::tuple<int const&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} + +void test_with_inner_alloc() +{ + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 1>; + using U = UsesAllocatorV2<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int&, int const&&>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + PairIn in(x, std::move(y)); + A.construct(ptr, std::move(in)); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&>&&, + std::tuple<int const&&, SAInner&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } + PInner.reset(); + POuter.reset(); + { + using T = UsesAllocatorV3<VoidAlloc2, 1>; + using U = NotUsesAllocator<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + using PairIn = std::pair<int, int const &>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + PairIn in(x, y); + A.construct(ptr, std::move(in)); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&&>&&, + std::tuple<int const&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} +int main() { + test_no_inner_alloc(); + test_with_inner_alloc(); +} diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp new file mode 100644 index 00000000000..840f4ecc616 --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// The 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 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class U1, class U2, class Tp, class Vp> +// void scoped_allocator_adaptor::construct(pair<U1, U2>*, Tp&&, Up&&) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + + +void test_no_inner_alloc() +{ + using VoidAlloc = CountingAllocator<void>; + AllocController P; + { + using T = UsesAllocatorV1<VoidAlloc, 1>; + using U = UsesAllocatorV2<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr, x, std::move(y)); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast, CA)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&>&&, + std::tuple<int const&&, SA&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + + } + P.reset(); + { + using T = UsesAllocatorV3<VoidAlloc, 1>; + using U = NotUsesAllocator<VoidAlloc, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Alloc = CountingAllocator<Pair>; + using SA = std::scoped_allocator_adaptor<Alloc>; + static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Alloc CA(P); + SA A(CA); + A.construct(ptr, std::move(x), y); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, CA)); + assert(checkConstruct<int const&>(ptr->second, UA_None)); + assert((P.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SA&, int&&>&&, + std::tuple<int const&>&& + >(CA, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} + +void test_with_inner_alloc() +{ + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 1>; + using U = UsesAllocatorV2<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + int x = 42; + int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr, x, std::move(y)); + assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int &&>(ptr->second, UA_AllocLast)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&>&&, + std::tuple<int &&, SAInner&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } + PInner.reset(); + POuter.reset(); + { + using T = UsesAllocatorV3<VoidAlloc2, 1>; + using U = NotUsesAllocator<VoidAlloc2, 1>; + using Pair = std::pair<T, U>; + int x = 42; + const int y = 101; + using Outer = CountingAllocator<Pair, 1>; + using Inner = CountingAllocator<Pair, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + A.construct(ptr, std::move(x), std::move(y)); + assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, I)); + assert(checkConstruct<int const&&>(ptr->second, UA_None)); + assert((POuter.checkConstruct<std::piecewise_construct_t const&, + std::tuple<std::allocator_arg_t, SAInner&, int&&>&&, + std::tuple<int const&&>&& + >(O, ptr))); + A.destroy(ptr); + std::free(ptr); + } +} +int main() { + test_no_inner_alloc(); + test_with_inner_alloc(); +} diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp new file mode 100644 index 00000000000..867cc74082e --- /dev/null +++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// The 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 + +// <scoped_allocator> + +// template <class OtherAlloc, class ...InnerAlloc> +// class scoped_allocator_adaptor + +// template <class T, class ...Args> +// void scoped_allocator_adaptor::construct(T*, Args&&...) + +#include <scoped_allocator> +#include <type_traits> +#include <utility> +#include <tuple> +#include <cassert> +#include <cstdlib> +#include "uses_alloc_types.hpp" +#include "controlled_allocators.hpp" + +// — If uses_allocator_v<T, inner_allocator_type> is false and +// is_constructible_v<T, Args...> is true, calls +// OUTERMOST_ALLOC_TRAITS(*this)::construct( +// OUTERMOST (*this), p, std::forward<Args>(args)...). +void test_bullet_one() { + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = NotUsesAllocator<VoidAlloc2, 3>; + using Outer = CountingAllocator<T, 1>; + using Inner = CountingAllocator<T, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(!std::uses_allocator<T, Inner>::value, ""); + T* ptr = (T*)::operator new(sizeof(T)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + int x = 42; + int const& cx = x; + A.construct(ptr, x, cx, std::move(x)); + assert((checkConstruct<int&, int const&, int&&>(*ptr, UA_None))); + assert((POuter.checkConstruct<int&, int const&, int&&>(O, ptr))); + A.destroy(ptr); + ::operator delete((void*)ptr); + } + PInner.reset(); + POuter.reset(); +} + + +// Otherwise, if uses_allocator_v<T, inner_allocator_type> is true and +// is_constructible_v<T, allocator_arg_t, inner_allocator_type&, Args...> is +// true, calls OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST (*this), p, +// allocator_arg, inner_allocator(), std::forward<Args>(args)...). +void test_bullet_two() { + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV1<VoidAlloc2, 3>; + using Outer = CountingAllocator<T, 1>; + using Inner = CountingAllocator<T, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + T* ptr = (T*)::operator new(sizeof(T)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + int x = 42; + int const& cx = x; + A.construct(ptr, x, cx, std::move(x)); + assert((checkConstruct<int&, int const&, int&&>(*ptr, UA_AllocArg, I))); + assert((POuter.checkConstruct<std::allocator_arg_t const&, + SA::inner_allocator_type&, int&, int const&, int&&>(O, ptr))); + A.destroy(ptr); + ::operator delete((void*)ptr); + } + PInner.reset(); + POuter.reset(); +} + +// Otherwise, if uses_allocator_v<T, inner_allocator_type> is true and +// is_constructible_v<T, Args..., inner_allocator_type&> is true, calls +// OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST (*this), p, +// std::forward<Args>(args)..., inner_allocator()). +void test_bullet_three() { + using VoidAlloc1 = CountingAllocator<void, 1>; + using VoidAlloc2 = CountingAllocator<void, 2>; + + AllocController POuter; + AllocController PInner; + { + using T = UsesAllocatorV2<VoidAlloc2, 3>; + using Outer = CountingAllocator<T, 1>; + using Inner = CountingAllocator<T, 2>; + using SA = std::scoped_allocator_adaptor<Outer, Inner>; + using SAInner = std::scoped_allocator_adaptor<Inner>; + static_assert(!std::uses_allocator<T, Outer>::value, ""); + static_assert(std::uses_allocator<T, Inner>::value, ""); + T* ptr = (T*)::operator new(sizeof(T)); + Outer O(POuter); + Inner I(PInner); + SA A(O, I); + int x = 42; + int const& cx = x; + A.construct(ptr, x, cx, std::move(x)); + assert((checkConstruct<int&, int const&, int&&>(*ptr, UA_AllocLast, I))); + assert((POuter.checkConstruct< + int&, int const&, int&&, + SA::inner_allocator_type&>(O, ptr))); + A.destroy(ptr); + ::operator delete((void*)ptr); + } + PInner.reset(); + POuter.reset(); +} + +int main() { + test_bullet_one(); + test_bullet_two(); + test_bullet_three(); +} |