| 1 |
// PR c++/54191 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
struct B |
| 5 |
{}; |
| 6 |
|
| 7 |
struct D |
| 8 |
: private B |
| 9 |
{}; |
| 10 |
|
| 11 |
template<typename T> |
| 12 |
T &&declval(); |
| 13 |
|
| 14 |
|
| 15 |
template<typename From, typename = decltype(B{declval<From>()})> |
| 16 |
constexpr bool test_braced_cast_to_base(int) |
| 17 |
{ return true; } |
| 18 |
|
| 19 |
template<typename> |
| 20 |
constexpr bool test_braced_cast_to_base(bool) |
| 21 |
{ return false; } |
| 22 |
|
| 23 |
static_assert(!test_braced_cast_to_base<D>(0), ""); |
| 24 |
|
| 25 |
|
| 26 |
template<typename From, typename = decltype(D{declval<From>()})> |
| 27 |
constexpr bool test_braced_cast_to_derived(int) |
| 28 |
{ return true; } |
| 29 |
|
| 30 |
template<typename> |
| 31 |
constexpr bool test_braced_cast_to_derived(bool) |
| 32 |
{ return false; } |
| 33 |
|
| 34 |
static_assert(!test_braced_cast_to_derived<B>(0), ""); |
| 35 |
|
| 36 |
|
| 37 |
typedef B *PB; |
| 38 |
|
| 39 |
template<typename From, typename = decltype(PB{declval<From>()})> |
| 40 |
constexpr bool test_braced_cast_to_ptr_to_base(int) |
| 41 |
{ return true; } |
| 42 |
|
| 43 |
template<typename> |
| 44 |
constexpr bool test_braced_cast_to_ptr_to_base(bool) |
| 45 |
{ return false; } |
| 46 |
|
| 47 |
static_assert(!test_braced_cast_to_ptr_to_base<D *>(0), ""); |
| 48 |
|
| 49 |
|
| 50 |
typedef D *PD; |
| 51 |
|
| 52 |
template<typename From, typename = decltype(PD{declval<From>()})> |
| 53 |
constexpr bool test_braced_cast_to_ptr_to_derived(int) |
| 54 |
{ return true; } |
| 55 |
|
| 56 |
template<typename> |
| 57 |
constexpr bool test_braced_cast_to_ptr_to_derived(bool) |
| 58 |
{ return false; } |
| 59 |
|
| 60 |
static_assert(!test_braced_cast_to_ptr_to_derived<B *>(0), ""); |
| 61 |
|
| 62 |
|
| 63 |
template<typename From, typename To, |
| 64 |
typename = decltype(static_cast<To>(declval<From>()))> |
| 65 |
constexpr bool test_static_cast(int) |
| 66 |
{ return true; } |
| 67 |
|
| 68 |
template<typename, typename> |
| 69 |
constexpr bool test_static_cast(bool) |
| 70 |
{ return false; } |
| 71 |
|
| 72 |
static_assert(!test_static_cast<B &, D &>(0), ""); |
| 73 |
static_assert(!test_static_cast<B *, D *>(0), ""); |
| 74 |
|
| 75 |
|
| 76 |
template<typename From, typename To, |
| 77 |
typename = decltype(dynamic_cast<To>(declval<From>()))> |
| 78 |
constexpr bool test_dynamic_cast(int) |
| 79 |
{ return true; } |
| 80 |
|
| 81 |
template<typename, typename> |
| 82 |
constexpr bool test_dynamic_cast(bool) |
| 83 |
{ return false; } |
| 84 |
|
| 85 |
static_assert(!test_dynamic_cast<D &, B &>(0), ""); |
| 86 |
static_assert(!test_dynamic_cast<D *, B *>(0), ""); |
| 87 |
|
| 88 |
|
| 89 |
int B::*pm = 0; |
| 90 |
|
| 91 |
template<typename T, typename = decltype(declval<T>().*pm)> |
| 92 |
constexpr bool test_member_ptr_dot(int) |
| 93 |
{ return true; } |
| 94 |
|
| 95 |
template<typename> |
| 96 |
constexpr bool test_member_ptr_dot(bool) |
| 97 |
{ return false; } |
| 98 |
|
| 99 |
static_assert(!test_member_ptr_dot<D>(0), ""); |
| 100 |
|
| 101 |
|
| 102 |
template<typename T, typename = decltype(declval<T>()->*pm)> |
| 103 |
constexpr bool test_member_ptr_arrow(int) |
| 104 |
{ return true; } |
| 105 |
|
| 106 |
template<typename> |
| 107 |
constexpr bool test_member_ptr_arrow(bool) |
| 108 |
{ return false; } |
| 109 |
|
| 110 |
static_assert(!test_member_ptr_arrow<D *>(0), ""); |
| 111 |
|
| 112 |
|
| 113 |
template<typename T, typename U, |
| 114 |
typename = decltype(declval<T>() < declval<U>())> |
| 115 |
constexpr bool test_rel_op(int) |
| 116 |
{ return true; } |
| 117 |
|
| 118 |
template<typename, typename> |
| 119 |
constexpr bool test_rel_op(bool) |
| 120 |
{ return false; } |
| 121 |
|
| 122 |
static_assert(!test_rel_op<D *, B *>(0), ""); |
| 123 |
|
| 124 |
|
| 125 |
template<typename T, typename U, |
| 126 |
typename = decltype(declval<T>() == declval<U>())> |
| 127 |
constexpr bool test_eq(int) |
| 128 |
{ return true; } |
| 129 |
|
| 130 |
template<typename, typename> |
| 131 |
constexpr bool test_eq(bool) |
| 132 |
{ return false; } |
| 133 |
|
| 134 |
static_assert(!test_eq<D *, B *>(0), ""); |
| 135 |
|
| 136 |
|
| 137 |
template<typename T, typename U, |
| 138 |
typename = decltype(false ? declval<T>() : declval<U>())> |
| 139 |
constexpr bool test_cond_op(int) |
| 140 |
{ return true; } |
| 141 |
|
| 142 |
template<typename, typename> |
| 143 |
constexpr bool test_cond_op(bool) |
| 144 |
{ return false; } |
| 145 |
|
| 146 |
static_assert(!test_cond_op<B *, D *>(0), ""); |