From patchwork Fri Apr 25 19:35:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 342986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A315C140134 for ; Sat, 26 Apr 2014 05:35:55 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; q=dns; s= default; b=u1nzaI/AGd8XWtuLTqSFYIEeiA0p9wosQjxH3n+wwiICfq3k67Y1t 661txFnlU09cUjLTtdRh53QSqktwaKMDtW6LKAhILgkZQ48K+gyQn6bPOokzBgYe Ho2VjYo1qEGQ5gHpUYVVZ3L1soikQPDnX86cc4/tETGg63KLkNGIQM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; s=default; bh=L8pyjYL8j+9peqJ7597/ndhnjKU=; b=p0AkMRUmEZ1Lmd1ETb7uzAAGJR1U TKIwKbCWto06Qc8ICTJOGwVzruTDL++16RyYaDOnlpJ3NMI1Epo0RIpiJl1br5C7 G6t8f2j9Y9JyBd4pEmJyGtC/8Yu+pQy8OtfaMMfR6hL1nKDphgyMPn2DfN2lgxsu zKs85nW7E3tx1+A= Received: (qmail 8638 invoked by alias); 25 Apr 2014 19:35:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 8617 invoked by uid 89); 25 Apr 2014 19:35:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Apr 2014 19:35:45 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3PJZf4r020940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Apr 2014 15:35:41 -0400 Received: from localhost (vpn1-5-114.ams2.redhat.com [10.36.5.114]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3PJZej7014696; Fri, 25 Apr 2014 15:35:40 -0400 Date: Fri, 25 Apr 2014 20:35:39 +0100 From: Jonathan Wakely To: Lars Gullik =?iso-8859-1?Q?Bj=F8nnes?= Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: std::experimental::optional operator!= Message-ID: <20140425193539.GK928@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) On 30/03/14 12:54 +0200, Lars Gullik Bjønnes wrote: >When trying to convert some code using boost::optional to using >std::experimental::optional instead if come over the issue that I had to >implement operator!= for the contained types. > >When looking at n3793 it states that operator!= should be implemented >with !(t1 == t2), and not t1 != t2 as the implementation in gcc 4.9 is >doing. This is the case for both the operator!= implementation where >optional is compared against T. > >The other operators look ok, and only operator== and operator< are used >in their implementations. > >Can this be fixed before 4.9? I've committed the patch from PR 60710 (attached) and will apply it to the 4.9 branch too. Tested x86_64-linux. commit ca00614d7bca5305905073dd558c6efacfb029ad Author: Jonathan Wakely Date: Fri Apr 25 20:16:05 2014 +0100 2014-04-25 Lars Gullik Bjønnes PR libstdc++/60710 * include/experimental/optional (operator!=): Implement in terms of operator==. * testsuite/experimental/optional/relops/1.cc: Remove operator!=. * testsuite/experimental/optional/relops/2.cc: Likewise. * testsuite/experimental/optional/relops/3.cc: Likewise. * testsuite/experimental/optional/relops/4.cc: Likewise. * testsuite/experimental/optional/relops/5.cc: Likewise. * testsuite/experimental/optional/relops/6.cc: Likewise. diff --git a/libstdc++-v3/include/experimental/optional b/libstdc++-v3/include/experimental/optional index 5f2d93f..2a3f29d 100644 --- a/libstdc++-v3/include/experimental/optional +++ b/libstdc++-v3/include/experimental/optional @@ -736,12 +736,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template constexpr bool operator!=(const optional<_Tp>& __lhs, _Tp const& __rhs) - { return !__lhs || *__lhs != __rhs; } + { return !__lhs || !(*__lhs == __rhs); } template constexpr bool operator!=(const _Tp& __lhs, const optional<_Tp>& __rhs) - { return !__rhs || __lhs != *__rhs; } + { return !__rhs || !(__lhs == *__rhs); } template constexpr bool diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/1.cc b/libstdc++-v3/testsuite/experimental/optional/relops/1.cc index f140880..3f1ee9c 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/1.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/1.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/2.cc b/libstdc++-v3/testsuite/experimental/optional/relops/2.cc index c7fc848..6ee9cba 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/2.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/2.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/3.cc b/libstdc++-v3/testsuite/experimental/optional/relops/3.cc index 9729000..581d016 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/3.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/3.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/4.cc b/libstdc++-v3/testsuite/experimental/optional/relops/4.cc index 45378f6..ce16fcb 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/4.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/4.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/5.cc b/libstdc++-v3/testsuite/experimental/optional/relops/5.cc index 008409e..c01bba5 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/5.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/5.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/6.cc b/libstdc++-v3/testsuite/experimental/optional/relops/6.cc index b179140..a24622b 100644 --- a/libstdc++-v3/testsuite/experimental/optional/relops/6.cc +++ b/libstdc++-v3/testsuite/experimental/optional/relops/6.cc @@ -37,10 +37,6 @@ namespace ns { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } bool - operator!=(value_type const& lhs, value_type const& rhs) - { return !(lhs == rhs); } - - bool operator<(value_type const& lhs, value_type const& rhs) { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }