From patchwork Wed Apr 8 15:52:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1268156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hRFlNj7V; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48y81g6Wf1z9sTF for ; Thu, 9 Apr 2020 01:52:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED096388700B; Wed, 8 Apr 2020 15:52:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED096388700B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586361168; bh=dY4f2DIf2Ah/RE2anyttJVp5wfhZ4hbb/mWpJBc2MDU=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hRFlNj7VNHR71UVYqmxLm+kT9kyTNE/9reNVJ3tDNVQs6Z3lRoA18Fsigc3/W9imE O+hXdQvNHKaRWPXLQb9A8zkqLUFCiiCOdT/81R7m3hvPdazgVbCzM+Tu6t1K9dA24A ukLEuJLlcQcX2qmQWrLsIkWEP++Koguf0kPiBORA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 99A18385B835 for ; Wed, 8 Apr 2020 15:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99A18385B835 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-IAfdLiq0OaSTHAOLcs8ljA-1; Wed, 08 Apr 2020 11:52:32 -0400 X-MC-Unique: IAfdLiq0OaSTHAOLcs8ljA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E996413F7; Wed, 8 Apr 2020 15:52:31 +0000 (UTC) Received: from localhost (unknown [10.33.36.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9151A19C70; Wed, 8 Apr 2020 15:52:31 +0000 (UTC) Date: Wed, 8 Apr 2020 16:52:30 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add comparison operators to types from Numerics clause Message-ID: <20200408155230.GU71320@redhat.com> References: <20200408151714.GA1248623@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200408151714.GA1248623@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-29.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "Li, Pan2 via Gcc-patches" Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Some more C++20 changes from P1614R2, "The Mothership has Landed". * include/bits/slice_array.h (operator==(const slice&, const slice&)): Define for C++20. * include/std/complex (operator==(const T&, const complex&)) (operator!=(const complex&, const complex&)) (operator!=(const complex&, const T&)) (operator!=(const T&, const complex&)): Do not declare for C++20. * testsuite/26_numerics/slice/compare.cc: New test. Tested powerpc64le-linux, committed to master. commit ef389dadd4f082e13b076f14a123bf506e158da4 Author: Jonathan Wakely Date: Wed Apr 8 16:51:59 2020 +0100 libstdc++: Add comparison operators to types from Numerics clause Some more C++20 changes from P1614R2, "The Mothership has Landed". * include/bits/slice_array.h (operator==(const slice&, const slice&)): Define for C++20. * include/std/complex (operator==(const T&, const complex&)) (operator!=(const complex&, const complex&)) (operator!=(const complex&, const T&)) (operator!=(const T&, const complex&)): Do not declare for C++20. * testsuite/26_numerics/slice/compare.cc: New test. diff --git a/libstdc++-v3/include/bits/slice_array.h b/libstdc++-v3/include/bits/slice_array.h index 32ba802c007..de33342e252 100644 --- a/libstdc++-v3/include/bits/slice_array.h +++ b/libstdc++-v3/include/bits/slice_array.h @@ -78,6 +78,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Return array stride of slice. size_t stride() const; +#if __cpp_impl_three_way_comparison >= 201907L + /// Equality comparison + friend bool operator==(const slice&, const slice&) = default; +#endif + private: size_t _M_off; // offset size_t _M_sz; // size diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index 4f170dc524a..f2917b8c368 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -468,6 +468,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator==(const complex<_Tp>& __x, const _Tp& __y) { return __x.real() == __y && __x.imag() == _Tp(); } +#if !(__cpp_impl_three_way_comparison >= 201907L) template inline _GLIBCXX_CONSTEXPR bool operator==(const _Tp& __x, const complex<_Tp>& __y) @@ -490,6 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline _GLIBCXX_CONSTEXPR bool operator!=(const _Tp& __x, const complex<_Tp>& __y) { return __x != __y.real() || _Tp() != __y.imag(); } +#endif //@} /// Extraction operator for complex values. diff --git a/libstdc++-v3/testsuite/26_numerics/slice/compare.cc b/libstdc++-v3/testsuite/26_numerics/slice/compare.cc new file mode 100644 index 00000000000..4459cf22eb6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/slice/compare.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2020 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-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +#include +#include + +void +test01() +{ + std::slice s1(1, 2, 3); + VERIFY( s1 == s1 ); + VERIFY( !(s1 != s1) ); + std::slice s2(1, 2, 3); + VERIFY( s2 == s1 ); + VERIFY( !(s2 != s1) ); + std::slice s3(3, 2, 3); + VERIFY( s3 != s1 ); + VERIFY( !(s3 == s1) ); + std::slice s4(1, 3, 3); + VERIFY( s4 != s1 ); + VERIFY( !(s4 == s1) ); + std::slice s5(1, 2, 4); + VERIFY( s5 != s1 ); + VERIFY( !(s5 == s1) ); +} + +int +main() +{ + test01(); +}