| 1 | // { dg-do compile { target c++11 } } |
| 2 | // { dg-require-effective-target hosted } |
| 3 | |
| 4 | #include <scoped_allocator> |
| 5 | |
| 6 | template<typename T> |
| 7 | struct Alloc |
| 8 | { |
| 9 | using value_type = T; |
| 10 | |
| 11 | Alloc() noexcept(false) { } |
| 12 | Alloc(const Alloc&) noexcept(false) { } |
| 13 | template<typename U> Alloc(const Alloc<U>&) noexcept { } |
| 14 | |
| 15 | T* allocate(std::size_t); |
| 16 | void deallocate(T*, std::size_t); |
| 17 | |
| 18 | bool operator==(const Alloc&) const noexcept(false) { return true; } |
| 19 | bool operator!=(const Alloc&) const noexcept(false) { return false; } |
| 20 | }; |
| 21 | |
| 22 | using A1 = std::allocator<int>; |
| 23 | using A2 = std::allocator<long>; |
| 24 | using Ax = Alloc<int>; |
| 25 | using SA1 = std::scoped_allocator_adaptor<A1, Ax>; |
| 26 | using SA2 = std::scoped_allocator_adaptor<A2, Ax>; |
| 27 | static_assert( std::is_default_constructible<SA1>::value |
| 28 | && ! std::is_nothrow_default_constructible<SA1>::value, |
| 29 | "default constructor is potentially-throwing" ); |
| 30 | static_assert( std::is_nothrow_constructible<SA1, A1, Ax>::value, |
| 31 | "multi-arg constructor is non-throwing" ); |
| 32 | static_assert( std::is_nothrow_copy_constructible<SA1>::value, |
| 33 | "copy constructor is non-throwing" ); |
| 34 | static_assert( std::is_nothrow_move_constructible<SA1>::value, |
| 35 | "move constructor is non-throwing" ); |
| 36 | static_assert( std::is_nothrow_constructible<SA1, const SA2&>::value, |
| 37 | "converting copy constructor is non-throwing" ); |
| 38 | static_assert( std::is_nothrow_constructible<SA1, SA2>::value, |
| 39 | "converting move constructor is non-throwing" ); |
| 40 | |
| 41 | static_assert( noexcept(std::declval<SA1&>().inner_allocator()), |
| 42 | "inner_allocator() is non-throwing" ); |
| 43 | static_assert( noexcept(std::declval<const SA1&>().inner_allocator()), |
| 44 | "inner_allocator() const is non-throwing" ); |
| 45 | static_assert( noexcept(std::declval<SA1&>().outer_allocator()), |
| 46 | "outer_allocator() is non-throwing" ); |
| 47 | static_assert( noexcept(std::declval<const SA1&>().outer_allocator()), |
| 48 | "outer_allocator() const is non-throwing" ); |