From patchwork Fri Aug 30 09:44:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 271203 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A14E52C0082 for ; Fri, 30 Aug 2013 19:44:17 +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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=mTsQ3vhex27GaO6nN hQ3ZRIUqWYbSAaGEPIiZKTIsNQJzQZsavHk3JA82xUNSxq2AWbmqQ5NKW9LZzkdG 9UzUNWJ2KA1cUN4+Ta00PbGQuaEUKXpdthuK7/8VyyVA/RvB5ctQHeTkfYh45PS+ bN0HMSw+iI3HA5v5a3DVR37NUc= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=ndB8nkJKe2r7ncYAVfH5S2L +12I=; b=aVWHbi2rY5gMrOyP7SDdISPOia1G8zpVHdwkINTqj/RJmBKCTTEMvCx 7Mq1IJQrVcKtQBI2h8zT8YjTsU0SPb/bg7QvVHTl5+ekfcF9+TEE9Ez7d3RCRPzc bb+cwZcrGTttkhrGCVr8Voo887wYK+CGFp4XJTo6bInxvq5L997Q= Received: (qmail 11301 invoked by alias); 30 Aug 2013 09:44:11 -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 11284 invoked by uid 89); 30 Aug 2013 09:44:11 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 30 Aug 2013 09:44:11 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: userp1040.oracle.com Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r7U9i8bi030404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Aug 2013 09:44:08 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7U9i7SG006131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 30 Aug 2013 09:44:07 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7U9i7P0020885; Fri, 30 Aug 2013 09:44:07 GMT Received: from poldo4.casa (/79.36.29.22) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 30 Aug 2013 02:44:06 -0700 Message-ID: <52206964.5040406@oracle.com> Date: Fri, 30 Aug 2013 11:44:04 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: =?ISO-8859-1?Q?Fran=E7ois_Dumont?= CC: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: PR 58148 patch References: <521BB025.3040700@gmail.com> <521BBD4F.1040300@oracle.com> <521D0D5A.3060201@gmail.com> <521D1001.3080504@oracle.com> <521E4FD8.9030201@gmail.com> <521E627A.4060502@oracle.com> <521FA314.1040702@gmail.com> In-Reply-To: <521FA314.1040702@gmail.com> Hi, On 08/29/2013 09:37 PM, François Dumont wrote: > Indeed, I check the Standard about const_pointer, so here is another > attempt. > > Tested under Linux x86_64. > > 2013-08-29 François Dumont > > PR libstdc++/58148 > * include/debug/functions.h (__foreign_iterator_aux4): Use > sequence const_pointer as common type to compare pointers. Add a > fallback overload in case pointers cannot be cast to sequence > const_pointer. > * testsuite/23_containers/vector/modifiers/insert/58148.cc: New. > > Ok to commit ? Seems pretty good to me. I have been thinking: when the non-trivial __foreign_iterator_aux4 is selected it actually has available as the last two arguments std::addressof(*(__it._M_get_sequence()->_M_base().begin())) std::addressof(*__other) we could as well give the parameters names and avoid passing __other. Also, I think we can do everything with std::less. I'm attaching below something I quickly hacked, untested, see if you like it in case commit something similar. Thanks! Paolo. ////////////////////// Index: functions.h =================================================================== --- functions.h (revision 202068) +++ functions.h (working copy) @@ -36,7 +36,7 @@ #include // for __addressof and addressof #if __cplusplus >= 201103L # include // for less and greater_equal -# include // for common_type +# include // for is_lvalue_reference and __and_ #endif #include @@ -172,27 +172,28 @@ } #if __cplusplus >= 201103L - template + // Default implementation. + template inline bool __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>& __it, - _InputIterator __other, - _PointerType1, _PointerType2) + typename _Sequence::const_pointer __begin, + typename _Sequence::const_pointer __other) { - typedef typename std::common_type<_PointerType1, - _PointerType2>::type _PointerType; + typedef typename _Sequence::const_pointer _PointerType; constexpr std::less<_PointerType> __l{}; - constexpr std::greater_equal<_PointerType> __ge{}; - return (__l(std::addressof(*__other), - std::addressof(*(__it._M_get_sequence()->_M_base().begin()))) - || __ge(std::addressof(*__other), - std::addressof(*(__it._M_get_sequence()->_M_base().end() - - 1)) + 1)); + return (__l(__other, __begin) + || __l(std::addressof(*(__it._M_get_sequence()->_M_base().end() + - 1)), __other)); } - + + // Fallback when address type cannot be implicitely casted to sequence + // const_pointer. + template + inline bool + __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>&, ...) + { return true; } + template inline bool __foreign_iterator_aux3(const _Safe_iterator<_Iterator, _Sequence>& __it, @@ -209,12 +210,12 @@ - std::addressof(*(__it._M_get_sequence()->_M_base().begin())) == __it._M_get_sequence()->size() - 1) return (__foreign_iterator_aux4 - (__it, __other, + (__it, std::addressof(*(__it._M_get_sequence()->_M_base().begin())), std::addressof(*__other))); return true; } - + /* Fallback overload for which we can't say, assume it is valid. */ template inline bool @@ -223,7 +224,7 @@ std::false_type) { return true; } #endif - + /** Checks that iterators do not belong to the same sequence. */ template inline bool