| 1 |
// { dg-do run { target c++14 } } |
| 2 |
// { dg-require-effective-target net_ts_ip } |
| 3 |
|
| 4 |
#include <experimental/internet> |
| 5 |
#include <testsuite_common_types.h> |
| 6 |
#include <testsuite_hooks.h> |
| 7 |
|
| 8 |
using namespace std; |
| 9 |
|
| 10 |
template<typename C, typename T, typename P> |
| 11 |
void check_gettable_sockopt(P p, C c = C()) |
| 12 |
{ |
| 13 |
static_assert( is_same<decltype(declval<const C&>().level(p)), int>(), "" ); |
| 14 |
static_assert( noexcept(declval<const C&>().level(p)), "" ); |
| 15 |
|
| 16 |
static_assert( is_same<decltype(declval<const C&>().name(p)), int>(), "" ); |
| 17 |
static_assert( noexcept(declval<const C&>().name(p)), "" ); |
| 18 |
|
| 19 |
static_assert( is_same<decltype(declval<C&>().data(p)), void*>(), "" ); |
| 20 |
static_assert( noexcept(declval<C&>().data(p)), "" ); |
| 21 |
|
| 22 |
static_assert( is_same<decltype(declval<const C&>().size(p)), size_t>(), "" ); |
| 23 |
static_assert( noexcept(declval<const C&>().size(p)), "" ); |
| 24 |
|
| 25 |
static_assert( is_same<decltype(declval<C&>().resize(p, 0)), void>(), "" ); |
| 26 |
static_assert( ! noexcept(declval<C&>().resize(p, 0)), "" ); |
| 27 |
|
| 28 |
VERIFY(c.size(p) == sizeof(T)); |
| 29 |
} |
| 30 |
|
| 31 |
template<typename C, typename T, typename P> |
| 32 |
void check_settable_sockopt(P p, C c = C()) |
| 33 |
{ |
| 34 |
static_assert( is_same<decltype(declval<const C&>().level(p)), int>(), "" ); |
| 35 |
static_assert( noexcept(declval<const C&>().level(p)), "" ); |
| 36 |
|
| 37 |
static_assert( is_same<decltype(declval<const C&>().name(p)), int>(), "" ); |
| 38 |
static_assert( noexcept(declval<const C&>().name(p)), "" ); |
| 39 |
|
| 40 |
static_assert( is_same<decltype(declval<const C&>().data(p)), const void*>(), "" ); |
| 41 |
static_assert( noexcept(declval<const C&>().data(p)), "" ); |
| 42 |
|
| 43 |
static_assert( is_same<decltype(declval<C&>().size(p)), size_t>(), "" ); |
| 44 |
static_assert( noexcept(declval<C&>().size(p)), "" ); |
| 45 |
|
| 46 |
VERIFY(c.size(p) == sizeof(T)); |
| 47 |
} |
| 48 |
|
| 49 |
template<typename C, typename T = int> |
| 50 |
void check_boolean_sockopt() |
| 51 |
{ |
| 52 |
namespace ip = std::experimental::net::ip; |
| 53 |
#if __has_include(<netinet/in.h>) |
| 54 |
check_gettable_sockopt<C, T>(ip::tcp::v4()); |
| 55 |
check_settable_sockopt<C, T>(ip::tcp::v4()); |
| 56 |
#endif |
| 57 |
|
| 58 |
static_assert( is_destructible<C>(), "" ); |
| 59 |
static_assert( is_nothrow_default_constructible<C>(), "" ); |
| 60 |
static_assert( is_nothrow_copy_constructible<C>(), "" ); |
| 61 |
static_assert( is_nothrow_copy_assignable<C>(), "" ); |
| 62 |
|
| 63 |
static_assert( is_nothrow_constructible<C, bool>(), "" ); |
| 64 |
static_assert( is_nothrow_assignable<C&, bool>(), "" ); |
| 65 |
|
| 66 |
static_assert( is_same<decltype(declval<const C&>().value()), bool>(), "" ); |
| 67 |
static_assert( noexcept(declval<const C&>().value()), "" ); |
| 68 |
|
| 69 |
static_assert( is_same<decltype(static_cast<bool>(declval<const C&>())), bool>(), "" ); |
| 70 |
static_assert( noexcept(static_cast<bool>(declval<const C&>())), "" ); |
| 71 |
|
| 72 |
static_assert( is_same<decltype(!declval<const C&>()), bool>(), "" ); |
| 73 |
static_assert( noexcept(!declval<const C&>()), "" ); |
| 74 |
} |
| 75 |
|
| 76 |
template<typename C, typename T = int> |
| 77 |
void check_integer_sockopt() |
| 78 |
{ |
| 79 |
namespace ip = std::experimental::net::ip; |
| 80 |
#if __has_include(<netinet/in.h>) |
| 81 |
check_gettable_sockopt<C, T>(ip::tcp::v4()); |
| 82 |
check_settable_sockopt<C, T>(ip::tcp::v4()); |
| 83 |
#endif |
| 84 |
|
| 85 |
static_assert( is_destructible<C>(), "" ); |
| 86 |
static_assert( is_nothrow_default_constructible<C>(), "" ); |
| 87 |
static_assert( is_nothrow_copy_constructible<C>(), "" ); |
| 88 |
static_assert( is_nothrow_copy_assignable<C>(), "" ); |
| 89 |
|
| 90 |
static_assert( is_nothrow_constructible<C, int>(), "" ); |
| 91 |
static_assert( is_nothrow_assignable<C&, int>(), "" ); |
| 92 |
|
| 93 |
static_assert( is_same<decltype(declval<const C&>().value()), int>(), "" ); |
| 94 |
static_assert( noexcept(declval<const C&>().value()), "" ); |
| 95 |
} |
| 96 |
|
| 97 |
template<typename C> |
| 98 |
void check_mcast_sockopt(C& c) |
| 99 |
{ |
| 100 |
namespace ip = std::experimental::net::ip; |
| 101 |
static_assert( is_destructible<C>(), "" ); |
| 102 |
static_assert( is_copy_constructible<C>(), "" ); |
| 103 |
static_assert( is_copy_assignable<C>(), "" ); |
| 104 |
|
| 105 |
#if __has_include(<netinet/in.h>) |
| 106 |
check_settable_sockopt<C, ipv6_mreq>(ip::tcp::v6(), c); |
| 107 |
check_settable_sockopt<C, ip_mreq>(ip::tcp::v4(), c); |
| 108 |
#endif |
| 109 |
|
| 110 |
static_assert( is_nothrow_constructible<C, const ip::address&>(), "" ); |
| 111 |
static_assert( ! is_convertible<const ip::address&, C>(), "explicit" ); |
| 112 |
static_assert( is_nothrow_constructible<C, const ip::address_v4&>(), "" ); |
| 113 |
static_assert( ! is_convertible<const ip::address_v4&, C>(), "explicit" ); |
| 114 |
static_assert( is_nothrow_constructible<C, const ip::address_v4&, const ip::address_v4&>(), "" ); |
| 115 |
static_assert( is_nothrow_constructible<C, const ip::address_v6&>(), "" ); |
| 116 |
static_assert( ! is_convertible<const ip::address_v6&, C>(), "explicit" ); |
| 117 |
static_assert( is_nothrow_constructible<C, const ip::address_v6&, unsigned>(), "" ); |
| 118 |
} |
| 119 |
|
| 120 |
void test_option_types() |
| 121 |
{ |
| 122 |
namespace ip = std::experimental::net::ip; |
| 123 |
|
| 124 |
#if __has_include(<netinet/in.h>) |
| 125 |
#if __has_include(<netinet/tcp.h>) |
| 126 |
check_boolean_sockopt<ip::tcp::no_delay>(); |
| 127 |
#endif |
| 128 |
|
| 129 |
check_boolean_sockopt<ip::v6_only>(); |
| 130 |
|
| 131 |
check_integer_sockopt<ip::unicast::hops>(); |
| 132 |
|
| 133 |
ip::multicast::join_group join(ip::address_v4::any()); |
| 134 |
check_mcast_sockopt(join); |
| 135 |
|
| 136 |
ip::multicast::leave_group leave(ip::address_v4::any()); |
| 137 |
check_mcast_sockopt(leave); |
| 138 |
|
| 139 |
using outbound_if = ip::multicast::outbound_interface; |
| 140 |
outbound_if oif(ip::address_v4::any()); |
| 141 |
check_settable_sockopt<outbound_if, unsigned>(ip::tcp::v6(), oif); |
| 142 |
check_settable_sockopt<outbound_if, ::in_addr>(ip::tcp::v4(), oif); |
| 143 |
static_assert( is_destructible<outbound_if>(), "" ); |
| 144 |
static_assert( ! is_default_constructible<outbound_if>(), "" ); |
| 145 |
static_assert( is_nothrow_copy_constructible<outbound_if>(), "" ); |
| 146 |
static_assert( is_nothrow_copy_assignable<outbound_if>(), "" ); |
| 147 |
static_assert( is_nothrow_constructible<outbound_if, const ip::address_v4&>(), "" ); |
| 148 |
static_assert( ! is_convertible<const ip::address_v4&, outbound_if>(), "explicit" ); |
| 149 |
static_assert( is_nothrow_constructible<outbound_if, unsigned>(), "" ); |
| 150 |
static_assert( ! is_convertible<unsigned, outbound_if>(), "explicit" ); |
| 151 |
|
| 152 |
check_integer_sockopt<ip::multicast::hops>(); |
| 153 |
|
| 154 |
check_boolean_sockopt<ip::multicast::enable_loopback>(); |
| 155 |
#endif |
| 156 |
} |
| 157 |
|
| 158 |
int main() |
| 159 |
{ |
| 160 |
test_option_types(); |
| 161 |
} |