| 1 |
// { dg-do run { target c++14 } } |
| 2 |
// { dg-require-effective-target net_ts_ip } |
| 3 |
// { dg-add-options net_ts } |
| 4 |
|
| 5 |
#include <experimental/internet> |
| 6 |
#include <stdexcept> |
| 7 |
#include <testsuite_hooks.h> |
| 8 |
|
| 9 |
using std::experimental::net::ip::network_v6; |
| 10 |
using std::experimental::net::ip::address_v6; |
| 11 |
|
| 12 |
constexpr void |
| 13 |
test01() |
| 14 |
{ |
| 15 |
network_v6 n0; |
| 16 |
VERIFY( n0.address().is_unspecified() ); |
| 17 |
VERIFY( n0.prefix_length() == 0 ); |
| 18 |
} |
| 19 |
|
| 20 |
constexpr void |
| 21 |
test02() |
| 22 |
{ |
| 23 |
address_v6 a0; |
| 24 |
network_v6 n0{ a0, 0 }; |
| 25 |
VERIFY( n0.address() == a0 ); |
| 26 |
VERIFY( n0.prefix_length() == 0 ); |
| 27 |
|
| 28 |
address_v6 a1{ address_v6::bytes_type{ 1, 2, 4, 8, 16, 32, 64, 128, |
| 29 |
3, 7, 47, 71, 83, 165, 199, 255 } }; |
| 30 |
network_v6 n1{ a1, 99}; |
| 31 |
VERIFY( n1.address() == a1 ); |
| 32 |
VERIFY( n1.prefix_length() == 99 ); |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
test02_errors() |
| 37 |
{ |
| 38 |
address_v6 a0; |
| 39 |
try |
| 40 |
{ |
| 41 |
network_v6{a0, -1}; |
| 42 |
VERIFY(false); |
| 43 |
} |
| 44 |
catch(const std::out_of_range&) |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
try |
| 49 |
{ |
| 50 |
network_v6{a0, 129}; |
| 51 |
VERIFY(false); |
| 52 |
} |
| 53 |
catch(const std::out_of_range&) |
| 54 |
{ |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
constexpr bool |
| 59 |
test_constexpr() |
| 60 |
{ |
| 61 |
test01(); |
| 62 |
test02(); |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
int |
| 67 |
main() |
| 68 |
{ |
| 69 |
test01(); |
| 70 |
test02(); |
| 71 |
test02_errors(); |
| 72 |
|
| 73 |
static_assert( test_constexpr(), "valid in constant expressions" ); |
| 74 |
} |