From patchwork Fri Feb 24 14:28:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 61340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp940849wrd; Fri, 24 Feb 2023 06:31:10 -0800 (PST) X-Google-Smtp-Source: AK7set9WYDYm3VFhji5zHUbKN9dVSV14s7jIEve2PoeEpaJCStZXYP6R0ga4xz74j5GNAeLKakiO X-Received: by 2002:a17:906:f0d1:b0:888:5d34:dc79 with SMTP id dk17-20020a170906f0d100b008885d34dc79mr24437099ejb.40.1677249069919; Fri, 24 Feb 2023 06:31:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677249069; cv=none; d=google.com; s=arc-20160816; b=uG0QUwIKRHu0XHq90V0+2fh2YpPO0fJf4tIZQT1v6ZpjG9nvZI7aGRRiMc8sL9fulS xrkyGd/8HJ6aWwCE+qwA0GYqqVfAHkS764h/c+53dBZkiQNMu+XhnghK+SnfBcwTq4la TO7M1drUF4mtF6CQa/quri7+c05d5/wCdLu61qosoVVYzB5GPz2sQAnedtjIC3wvZc6L /oQoDMo5GCmWxYoYzxZIv7/somCIiUAiYVKsGIJ5SM/5vqcQAnTijzeEIsXLEhgph2f9 aKSE9Qgk7tgV1vU6Ouli9k9eOBcuVK4msIIF7cuKaGBzQljA11PFQt+i3gdhXlIGVrCv WlPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=dk0tv7r9k/K3CeXmEk6Ae5cAIfomNZnNjUGCY5on+I4=; b=V3aiqLjNpWMbi5R+gW3xXkcBbqmCf4VkWAnDqp5tWiDFC8Y1KMjoWSr/X2zWgycxow qVXLBFs6pEwGy+MmpOuVAV8l8T3QfGenGXGJTvuPx+o/p0e8PgpbaH1JoBH6c9LegO/J CRxxQpwkFdcumOsZsKef86kARmXWhWzVuvhuDuijZKUdb7FEdDqiSFgb73HMD1zf1l1g 3Ivr1KT7Y8RKSGoEl1VgbWWBg6McK+HndueSFMtb6gI+Gl8pIfsART8D9xEQ9JaJpmeq 77GSNWzLXGQzJnAgNyZad3Z9acTTA5ELDrEsBoSBGlOYBg5m7xVMmfoCbKvS3V4fPIRv OsTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2CUZt3X; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id wd3-20020a170907d60300b008eeba611028si6638297ejc.478.2023.02.24.06.31.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 06:31:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2CUZt3X; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77B84384F02F for ; Fri, 24 Feb 2023 14:29:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77B84384F02F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677248973; bh=dk0tv7r9k/K3CeXmEk6Ae5cAIfomNZnNjUGCY5on+I4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=f2CUZt3Xhwa4KqTDbqsxUYyA/4mIrC+M+MS654tqueWNU0RcGIyvPcKmF40rUEOiq /FLZSDaE+GktLszbg8v/5i9e/Y1oO8neAaVYMyNDrPbfs4LPOmGmkcr2ZqlsAhRoir AuL6DW5Ypi6GK105iz40kLBvLFMQRpg8vcXNdqYM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CD9B1385480C for ; Fri, 24 Feb 2023 14:28:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD9B1385480C Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-MtZAc2HsNNOd6t2Y_o04Og-1; Fri, 24 Feb 2023 09:28:12 -0500 X-MC-Unique: MtZAc2HsNNOd6t2Y_o04Og-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8A62101A521; Fri, 24 Feb 2023 14:28:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9272B404BEC0; Fri, 24 Feb 2023 14:28:11 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 4/5] libstdc++: Make net::ip::basic_endpoint comparisons constexpr Date: Fri, 24 Feb 2023 14:28:07 +0000 Message-Id: <20230224142808.714075-4-jwakely@redhat.com> In-Reply-To: <20230224142808.714075-1-jwakely@redhat.com> References: <20230224142808.714075-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758723120861268888?= X-GMAIL-MSGID: =?utf-8?q?1758723120861268888?= Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * include/experimental/internet (basic_endpoint): Add missing constexpr to comparison operators. * testsuite/experimental/net/internet/endpoint/cons.cc: New test. --- libstdc++-v3/include/experimental/internet | 12 ++-- .../net/internet/endpoint/cons.cc | 66 +++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc 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; + }; +}