From patchwork Thu Aug 29 19:37:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 270900 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 016FA2C009D for ; Fri, 30 Aug 2013 05:38:08 +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=naQUZmMsqDggPiQk6 2IGPCFRW5JF10mVSE23hYDLL0qh8Svt7lvoOgH4X1PVGZwfso2ybF0wEeOA96nnX 9bRR7wduTpuKYE6KZWFe3lVn/fQljVBNp288gHKN5ETMcFxOu20dbC/KmOo6yiRW jYg34I3vzs3Ks4jQdDtWr6Qu/g= 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=8dxS7OMp7KRmbuLMC869Lv3 pTv0=; b=E8vRbm1X3w0y/zPaWJdjs0FZMr3x6dlpTb9StNubqLltziO1VFIZNMD 07S2WllcPMwSjNngeHU/yFwaELRLdi73I1TermhfeNs3+BWYF/MAl17n9u7V9gOf HTZiSw3Y+Her95yyORQ9gn/4bHeMMj0P96tD/bCnA0kpeufi6bS8= Received: (qmail 7041 invoked by alias); 29 Aug 2013 19:38:02 -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 7024 invoked by uid 89); 29 Aug 2013 19:38:02 -0000 Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 29 Aug 2013 19:38:02 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, FREEMAIL_FROM, KHOP_THREADED autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wi0-f171.google.com Received: by mail-wi0-f171.google.com with SMTP id hq12so1006422wib.10 for ; Thu, 29 Aug 2013 12:37:58 -0700 (PDT) X-Received: by 10.180.109.35 with SMTP id hp3mr16183702wib.52.1377805078420; Thu, 29 Aug 2013 12:37:58 -0700 (PDT) Received: from localhost.localdomain (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by mx.google.com with ESMTPSA id om9sm14824107wic.8.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Aug 2013 12:37:57 -0700 (PDT) Message-ID: <521FA314.1040702@gmail.com> Date: Thu, 29 Aug 2013 21:37:56 +0200 From: =?ISO-8859-1?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120829 Thunderbird/15.0 MIME-Version: 1.0 To: Paolo Carlini 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> In-Reply-To: <521E627A.4060502@oracle.com> 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 ? François On 08/28/2013 10:50 PM, Paolo Carlini wrote: > Hi, > > On 08/28/2013 09:30 PM, François Dumont wrote: >> - std::addressof(*(__it._M_get_sequence()->_M_base().begin()))) >> + &(*(__it._M_get_sequence()->_M_base().begin()))) > I'm not convinced that you can avoid these std::addressof: it seems to > me that the value_type can still have an overloaded operator& > > Paolo. > Index: include/debug/functions.h =================================================================== --- include/debug/functions.h (revision 201966) +++ include/debug/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,17 +172,16 @@ } #if __cplusplus >= 201103L + // Default implementation. template + typename _InputIterator> inline bool __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>& __it, _InputIterator __other, - _PointerType1, _PointerType2) + typename _Sequence::const_pointer, + typename _Sequence::const_pointer) { - 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{}; @@ -192,7 +191,16 @@ std::addressof(*(__it._M_get_sequence()->_M_base().end() - 1)) + 1)); } - + + // Fallback when address type cannot be implicitely casted to sequence + // const_pointer. + template + inline bool + __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>&, + _InputIterator, ...) + { return true; } + template inline bool __foreign_iterator_aux3(const _Safe_iterator<_Iterator, _Sequence>& __it, @@ -223,7 +231,7 @@ std::false_type) { return true; } #endif - + /** Checks that iterators do not belong to the same sequence. */ template inline bool Index: testsuite/23_containers/vector/modifiers/insert/58148.cc =================================================================== --- testsuite/23_containers/vector/modifiers/insert/58148.cc (revision 0) +++ testsuite/23_containers/vector/modifiers/insert/58148.cc (revision 0) @@ -0,0 +1,35 @@ +// Copyright (C) 2013 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++11" } +// { dg-do compile } + +#include + +void +test01() +{ + std::vector v; + char c = 'a'; + v.insert(v.begin(), &c, &c); +} + +int main() +{ + test01(); + return 0; +}