#endif
// static members:
+
static constexpr address_v6
any() noexcept
{
- address_v6 __addr;
- __builtin_memcpy(&__addr._M_bytes, in6addr_any.s6_addr, 16);
- return __addr;
+ return {};
}
static constexpr address_v6
loopback() noexcept
{
address_v6 __addr;
- __builtin_memcpy(&__addr._M_bytes, in6addr_loopback.s6_addr, 16);
+ __addr._M_bytes[15] = 1;
return __addr;
}
__str++;
}
if (__out == std::end(__buf))
- __ec = std::make_error_code(std::errc::invalid_argument);
+ {
+ __ec = std::make_error_code(std::errc::invalid_argument);
+ return {};
+ }
else
{
*__out = '\0';
__n++;
}
if (__out == std::end(__buf))
- __ec = std::make_error_code(std::errc::invalid_argument);
+ {
+ __ec = std::make_error_code(std::errc::invalid_argument);
+ return {};
+ }
else
{
*__out = '\0';
__n++;
}
if (__out == std::end(__buf))
- __ec = std::make_error_code(std::errc::invalid_argument);
+ {
+ __ec = std::make_error_code(std::errc::invalid_argument);
+ return {};
+ }
else
{
*__out = '\0';
// { dg-add-options net_ts }
#include <experimental/internet>
+#include <sstream>
#include <testsuite_hooks.h>
using std::experimental::net::ip::address_v4;
-void
+constexpr bool
test01()
{
- bool test __attribute__((unused)) = false;
-
address_v4 a;
VERIFY( a.is_unspecified() );
a = address_v4::broadcast();
VERIFY( !a.is_unspecified() );
+
+ return true;
}
-void
+static_assert(test01(), "");
+
+constexpr bool
test02()
{
- bool test __attribute__((unused)) = false;
-
auto a = address_v4::loopback();
VERIFY( a.is_loopback() );
a = address_v4::broadcast();
VERIFY( !a.is_loopback() );
+
+ return true;
}
-void
+static_assert(test02(), "");
+
+constexpr bool
test03()
{
- bool test __attribute__((unused)) = false;
-
auto a = address_v4{0xE0000001};
VERIFY( a.is_multicast() );
a = address_v4{0xDFFFFFFF};
VERIFY( !a.is_multicast() );
+
+ return true;
}
+static_assert(test03(), "");
+
void
test04()
{
- bool test __attribute__((unused)) = false;
-
VERIFY( address_v4::any().to_string() == "0.0.0.0" );
VERIFY( address_v4::loopback().to_string() == "127.0.0.1" );
VERIFY( address_v4::broadcast().to_string() == "255.255.255.255" );
void
test05()
{
- bool test __attribute__((unused)) = false;
-
std::ostringstream ss;
ss << address_v4::any() << ' ' << address_v4::loopback() << ' '
<< address_v4::broadcast();
VERIFY( ss.str() == "0.0.0.0 127.0.0.1 255.255.255.255" );
}
-
int
main()
{
--- /dev/null
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++14 } }
+// { dg-add-options net_ts }
+
+#include <experimental/internet>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+using std::experimental::net::ip::address_v6;
+
+constexpr bool
+test01()
+{
+ address_v6 a;
+ VERIFY( a.is_unspecified() );
+ VERIFY( !a.is_loopback() );
+ VERIFY( !a.is_multicast() );
+ VERIFY( !a.is_link_local() );
+ VERIFY( !a.is_site_local() );
+
+ a = address_v6::any();
+ VERIFY( a.is_unspecified() );
+ VERIFY( !a.is_loopback() );
+ VERIFY( !a.is_multicast() );
+ VERIFY( !a.is_link_local() );
+ VERIFY( !a.is_site_local() );
+
+ a = address_v6::loopback();
+ VERIFY( !a.is_unspecified() );
+ VERIFY( a.is_loopback() );
+ VERIFY( !a.is_multicast() );
+ VERIFY( !a.is_link_local() );
+ VERIFY( !a.is_site_local() );
+
+ a = address_v6{address_v6::loopback().to_bytes(), 1};
+ VERIFY( !a.is_unspecified() );
+ VERIFY( !a.is_loopback() );
+ VERIFY( !a.is_multicast() );
+ VERIFY( !a.is_link_local() );
+ VERIFY( !a.is_site_local() );
+
+ return true;
+}
+
+static_assert(test01(), "");
+
+constexpr bool
+test02()
+{
+ auto a = address_v6{address_v6::bytes_type{0xFF}};
+ VERIFY( a.is_multicast() );
+
+ a = address_v6{address_v6::bytes_type{0xFF, 0x01}};
+ VERIFY( a.is_multicast() );
+
+ a = address_v6{address_v6::bytes_type{0xFF, 0x00, 0x01}};
+ VERIFY( a.is_multicast() );
+
+ a = address_v6{address_v6::bytes_type{0xFE, 0x80}};
+ VERIFY( !a.is_multicast() );
+
+ a = address_v6{address_v6::bytes_type{0xFE, 0xC0}};
+ VERIFY( !a.is_multicast() );
+
+ return true;
+}
+
+static_assert(test02(), "");
+
+void
+test03()
+{
+ VERIFY( address_v6::any().to_string() == "::" );
+ VERIFY( address_v6::loopback().to_string() == "::1" );
+}
+
+void
+test04()
+{
+ std::ostringstream ss;
+ ss << address_v6::any() << ' ' << address_v6::loopback();
+ VERIFY( ss.str() == ":: ::1" );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+}