From 970ba719250ec06767e0617658bb92a64fde0f3f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 12 Feb 2021 13:01:20 +0000 Subject: [PATCH] libstdc++: Fix errors in 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. --- 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(-) create mode 100644 libstdc++-v3/testsuite/experimental/net/internet/address/v6/members.cc diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index 2fc253395f5..57831676a29 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 12c269b4af2..c82f30cd119 100644 --- a/libstdc++-v3/include/experimental/io_context +++ b/libstdc++-v3/include/experimental/io_context @@ -680,10 +680,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 f0eff14f202..f644c0847ab 100644 --- a/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc +++ b/libstdc++-v3/testsuite/experimental/net/internet/address/v4/members.cc @@ -19,15 +19,14 @@ // { dg-add-options net_ts } #include +#include #include using std::experimental::net::ip::address_v4; -void +constexpr bool test01() { - bool test __attribute__((unused)) = false; - address_v4 a; VERIFY( a.is_unspecified() ); @@ -39,13 +38,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() ); @@ -63,13 +64,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() ); @@ -84,13 +87,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" ); @@ -99,15 +104,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 +// . + +// { dg-do run { target c++14 } } +// { dg-add-options net_ts } + +#include +#include +#include + +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(); +} -- 2.30.2