| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
#include <unordered_set> |
| 3 |
|
| 4 |
static_assert( std::is_default_constructible<std::unordered_set<int>>{}, "" ); |
| 5 |
|
| 6 |
template<typename T> |
| 7 |
struct NoDefaultConsAlloc |
| 8 |
{ |
| 9 |
using value_type = T; |
| 10 |
|
| 11 |
NoDefaultConsAlloc(int) noexcept { } |
| 12 |
|
| 13 |
template<typename U> |
| 14 |
NoDefaultConsAlloc(const NoDefaultConsAlloc<U>&) { } |
| 15 |
|
| 16 |
T *allocate(std::size_t n) |
| 17 |
{ return std::allocator<T>().allocate(n); } |
| 18 |
|
| 19 |
void deallocate(T *p, std::size_t n) |
| 20 |
{ std::allocator<T>().deallocate(p, n); } |
| 21 |
|
| 22 |
bool operator==(const NoDefaultConsAlloc&) const { return true; } |
| 23 |
bool operator!=(const NoDefaultConsAlloc&) const { return false; } |
| 24 |
}; |
| 25 |
|
| 26 |
using Set = std::unordered_set<int, std::hash<int>, std::equal_to<int>, |
| 27 |
NoDefaultConsAlloc<int>>; |
| 28 |
static_assert( ! std::is_default_constructible<Set>{}, "PR libstdc++/100863" ); |
| 29 |
|
| 30 |
struct Hash : std::hash<int> { Hash(int) { } }; |
| 31 |
using Set2 = std::unordered_set<int, Hash>; |
| 32 |
static_assert( ! std::is_default_constructible<Set2>{}, "PR libstdc++/100863" ); |
| 33 |
|
| 34 |
struct Equal : std::equal_to<int> { Equal(int) { } }; |
| 35 |
using Set3 = std::unordered_set<int, std::hash<int>, Equal>; |
| 36 |
static_assert( ! std::is_default_constructible<Set3>{}, "PR libstdc++/100863" ); |
| 37 |
|
| 38 |
// PR libstdc++/101583 |
| 39 |
// verify non-default ctors can still be used |
| 40 |
using Set4 = std::unordered_set<int, Hash, Equal, NoDefaultConsAlloc<int>>; |
| 41 |
Hash h(1); |
| 42 |
Equal eq(1); |
| 43 |
Set4::allocator_type a(1); |
| 44 |
Set4 s{1, h, eq, a}; |
| 45 |
Set4 s2{s.begin(), s.end(), s.size(), h, eq, a}; |
| 46 |
Set4 s3{{1, 2, 3}, 3, h, eq, a}; |
| 47 |
Set4 s4{s}; |
| 48 |
Set4 s5{s, a}; |
| 49 |
Set4 s6{std::move(s)}; |
| 50 |
Set4 s7{std::move(s6), a}; |