From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 96727384FB57; Fri, 24 Feb 2023 14:26:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96727384FB57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677248784; bh=hODi5dKEf/p86/BCnjcpHxJZZVQApMzee52piYNlkpU=; h=From:To:Subject:Date:From; b=IKgYcbIYUjQ8iyhBpWXiEU5ms1C3q50JQGrcqaC7eolATokvzSofZiiPE4i7+8iOv QHlT7aq7yK5plUu3loQu9vHypyxMWuTnYbp9sllHQv6Jn5McS9N3jPGwOx7rmiXaDi OxJiaXvC6A1bo9BWx356JnTcjMYulbmxMtwMAYgo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-6327] libstdc++: Make net::ip::basic_endpoint comparisons constexpr X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 80e9bac232fe4b8fcc815761a7c0932b0db49b25 X-Git-Newrev: 97111dccf97d8b4dbf7c1ef11c72827295a72466 Message-Id: <20230224142624.96727384FB57@sourceware.org> Date: Fri, 24 Feb 2023 14:26:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:97111dccf97d8b4dbf7c1ef11c72827295a72466 commit r13-6327-g97111dccf97d8b4dbf7c1ef11c72827295a72466 Author: Jonathan Wakely Date: Fri Feb 24 13:00:41 2023 +0000 libstdc++: Make net::ip::basic_endpoint comparisons constexpr libstdc++-v3/ChangeLog: * include/experimental/internet (basic_endpoint): Add missing constexpr to comparison operators. * testsuite/experimental/net/internet/endpoint/cons.cc: New test. Diff: --- libstdc++-v3/include/experimental/internet | 12 ++-- .../experimental/net/internet/endpoint/cons.cc | 66 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet index 5336b8a8ce3..cae07f466da 100644 --- a/libstdc++-v3/include/experimental/internet +++ b/libstdc++-v3/include/experimental/internet @@ -1626,19 +1626,19 @@ namespace ip */ template - inline bool + constexpr bool operator==(const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { return __a.address() == __b.address() && __a.port() == __b.port(); } template - inline bool + constexpr bool operator!=(const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { return !(__a == __b); } template - inline bool + constexpr bool operator< (const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { @@ -1647,19 +1647,19 @@ namespace ip } template - inline bool + constexpr bool operator> (const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { return __b < __a; } template - inline bool + constexpr bool operator<=(const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { return !(__b < __a); } template - inline bool + constexpr bool operator>=(const basic_endpoint<_InternetProtocol>& __a, const basic_endpoint<_InternetProtocol>& __b) { return !(__a < __b); } diff --git a/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc b/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc new file mode 100644 index 00000000000..1b5c92c0b58 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc @@ -0,0 +1,66 @@ +// { dg-do run { target c++14 } } +// { dg-require-effective-target net_ts_ip } +// { dg-add-options net_ts } + +#include +#include + +using namespace std::experimental::net; + +constexpr void +test_default() +{ + ip::tcp::endpoint t1; + VERIFY( t1.protocol() == ip::tcp::v4() ); + VERIFY( t1.address() == ip::address() ); + VERIFY( t1.port() == 0 ); + + ip::udp::endpoint t2; + VERIFY( t2.protocol() == ip::udp::v4() ); + VERIFY( t2.address() == ip::address() ); + VERIFY( t2.port() == 0 ); +} + +constexpr void +test_proto() +{ + ip::tcp::endpoint t1(ip::tcp::v4(), 22); + VERIFY( t1.protocol() == ip::tcp::v4() ); + VERIFY( t1.address() == ip::address_v4() ); + VERIFY( t1.port() == 22 ); + + ip::tcp::endpoint t2(ip::tcp::v6(), 80); + VERIFY( t2.protocol() == ip::tcp::v6() ); + VERIFY( t2.address() == ip::address_v6() ); + VERIFY( t2.port() == 80 ); +} + +constexpr void +test_addr() +{ + ip::address_v4 a1(ip::address_v4::bytes_type(1, 2, 3, 4)); + ip::tcp::endpoint t1(a1, 22); + VERIFY( t1.protocol() == ip::tcp::v4() ); + VERIFY( t1.address() == a1 ); + VERIFY( t1.port() == 22 ); + + ip::address_v6 a2(ip::address_v6::bytes_type(21,22,23,24,25,26,27,28,29)); + ip::tcp::endpoint t2(a2, 80); + VERIFY( t2.protocol() == ip::tcp::v6() ); + VERIFY( t2.address() == a2 ); + VERIFY( t2.port() == 80 ); +} + +int main() +{ + test_default(); + test_proto(); + test_addr(); + + constexpr bool c = [] { + test_default(); + test_proto(); + test_addr(); + return true; + }; +}