public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9372] libstdc++: Fix errors in <experimental/internet>
@ 2021-04-20 18:52 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-04-20 18:52 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:af06fe692abd67a4d8a145f7b4da5a3a08768922
commit r9-9372-gaf06fe692abd67a4d8a145f7b4da5a3a08768922
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Feb 12 13:01:20 2021 +0000
libstdc++: Fix errors in <experimental/internet>
libstdc++-v3/ChangeLog:
* include/experimental/internet (address_v6::any): Avoid using
memcpy in constexpr function.
(address_v6::loopback): Likewise.
(make_address_v6): Fix missing return statements on error paths.
* include/experimental/io_context: Avoid -Wdangling-else
warning.
* testsuite/experimental/net/internet/address/v4/members.cc:
Remove unused variables.
* testsuite/experimental/net/internet/address/v6/members.cc:
New test.
(cherry picked from commit 970ba719250ec06767e0617658bb92a64fde0f3f)
Diff:
---
libstdc++-v3/include/experimental/internet | 22 +++--
libstdc++-v3/include/experimental/io_context | 10 +-
.../net/internet/address/v4/members.cc | 30 +++---
.../net/internet/address/v6/members.cc | 108 +++++++++++++++++++++
4 files changed, 145 insertions(+), 25 deletions(-)
diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet
index adb17c79f1a..3ae2e361e1e 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -354,19 +354,18 @@ namespace ip
#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;
}
@@ -755,7 +754,10 @@ namespace ip
__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';
@@ -790,7 +792,10 @@ namespace ip
__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';
@@ -835,7 +840,10 @@ namespace ip
__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';
diff --git a/libstdc++-v3/include/experimental/io_context b/libstdc++-v3/include/experimental/io_context
index 9ffba222bc0..70d43359a84 100644
--- a/libstdc++-v3/include/experimental/io_context
+++ b/libstdc++-v3/include/experimental/io_context
@@ -667,10 +667,12 @@ inline namespace v1
continue;
if (__res == __reactor::_S_timeout)
- if (__timerq == nullptr)
- return false;
- else
- continue; // timed out, so restart loop and process the timer
+ {
+ if (__timerq == nullptr)
+ return false;
+ else
+ continue; // timed out, so restart loop and process the timer
+ }
__timerq = nullptr;
diff --git a/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc b/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc
index 2d71581ac2e..ac72a6a9a16 100644
--- a/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc
+++ b/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc
@@ -20,15 +20,14 @@
// { dg-require-gthreads "" }
#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() );
@@ -40,13 +39,15 @@ test01()
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() );
@@ -64,13 +65,15 @@ test02()
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() );
@@ -85,13 +88,15 @@ test03()
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" );
@@ -100,15 +105,12 @@ test04()
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()
{
diff --git a/libstdc++-v3/testsuite/experimental/net/internet/address/v6/members.cc b/libstdc++-v3/testsuite/experimental/net/internet/address/v6/members.cc
new file mode 100644
index 00000000000..506345dc990
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/net/internet/address/v6/members.cc
@@ -0,0 +1,108 @@
+// 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();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-20 18:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 18:52 [gcc r9-9372] libstdc++: Fix errors in <experimental/internet> Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).