From patchwork Tue Oct 9 05:11:23 2018 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: 981029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487173-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qk5Rg1fO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EerE0eUx"; dkim-atps=neutral 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 42TlhN0lPKz9s8T for ; Tue, 9 Oct 2018 16:11:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=WgUuegm4apZgRuj/9gicqW5KtjteA5zrcdXSTA9lFjmrUDLsjM4ZC s30pwtz/EKxBxqHVQsqcFVyQdCcA9RSAXuseQFJZ3brUgfwxwJ/dfWygqL1Q0Y5J v7U7hrckZJp1ckRfSU3lke5cQZD/LnXqrr/n8enBXsvMRYrAx/D72M= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=nqDVx3iTX1HtmUa+u2f6xamqICQ=; b=qk5Rg1fOeBLoL+OoC5Yw ii5lOsvqx6PU66lydtHYKyrA+4hqKbDDFgj0A+diKCo0wlPx0rWwiecZ9vmYG2ua DRALIFOiPH+EqylqHON1XSQUB25m1Rm3LmHyds/bjVqx3Cva7TItmTp9sf/IoRFj SA0DwemKGMP7RrPWScP/IQQ= Received: (qmail 92366 invoked by alias); 9 Oct 2018 05:11:30 -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 92337 invoked by uid 89); 9 Oct 2018 05:11:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=yesterday's, yesterdays, HX-Received:sk:o7-v6mr, fdumontgccgnuorg X-HELO: mail-wr1-f46.google.com Received: from mail-wr1-f46.google.com (HELO mail-wr1-f46.google.com) (209.85.221.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Oct 2018 05:11:28 +0000 Received: by mail-wr1-f46.google.com with SMTP id w5-v6so285743wrt.2; Mon, 08 Oct 2018 22:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-language; bh=VDVDM8Wi6jqPMMpyFj1WgwHtziOid8xr6LdLX8A0Fyk=; b=EerE0eUxZT6J++9d3KVwa8NsowLYSgmii7kampZnekVsHDEVdPT2fcx50RpX3v20va de0lvgtND918iXuca9EXZdMfFmyUtka3yNgTRrJMc9GBlYgRFUqAokoI8aEyi+XtSNuJ ksC1POAJT3AiGfUaVMhlT2j6E5KHkRUS5DssWGhmcxWyxhceFNEQVCyrzt9rVeX6mfeS VfzS/MaEtZJLFh1krrhHdIdF5zmgc7P+FNsTcY47qWy6mXVQEP73vgx/VMHek0Dn+dOP dgJyfAdaN3CHz2fH1BfWOq24WYGMFQYU07h44mtRYCKJFt9qLyuNrj6pKhsAphRPRUL+ G91g== Received: from [10.126.8.104] ([109.190.253.11]) by smtp.googlemail.com with ESMTPSA id z16-v6sm10230114wmc.0.2018.10.08.22.11.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:11:24 -0700 (PDT) From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: [PATCH] __debug::list use C++11 direct initialization To: "libstdc++@gcc.gnu.org" , gcc-patches Message-ID: <926a61ca-121a-39c9-72fa-5327dd9ddc6b@gmail.com> Date: Tue, 9 Oct 2018 07:11:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Here is the communication for my yesterday's patch which I thought svn had failed to commit (I had to interrupt it). Similarly to what I've done for associative containers here is a cleanup of the std::__debug::list implementation leveraging more on C++11 direct initialization. I also made sure we use consistent comparison between iterator/const_iterator in erase and emplace methods. 2018-10-08  François Dumont     * include/debug/list (list<>::cbegin()): Use C++11 direct     initialization.     (list<>::cend()): Likewise.     (list<>::emplace<>(const_iterator, _Args&&...)): Likewise.     (list<>::insert(const_iterator, initializer_list<>)): Likewise.     (list<>::insert(const_iterator, size_type, const _Tp&)): Likewise.     (list<>::erase(const_iterator, const_iterator)): Ensure consistent     iterator comparisons.     (list<>::splice(const_iterator, list&&, const_iterator,     const_iterator)): Likewise. Tested under Linux x86_64 Debug mode and committed. François diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 8add1d596e0..879e1177497 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -244,11 +244,11 @@ namespace __debug #if __cplusplus >= 201103L const_iterator cbegin() const noexcept - { return const_iterator(_Base::begin(), this); } + { return { _Base::begin(), this }; } const_iterator cend() const noexcept - { return const_iterator(_Base::end(), this); } + { return { _Base::end(), this }; } const_reverse_iterator crbegin() const noexcept @@ -405,8 +405,8 @@ namespace __debug emplace(const_iterator __position, _Args&&... __args) { __glibcxx_check_insert(__position); - return iterator(_Base::emplace(__position.base(), - std::forward<_Args>(__args)...), this); + return { _Base::emplace(__position.base(), + std::forward<_Args>(__args)...), this }; } #endif @@ -430,7 +430,7 @@ namespace __debug insert(const_iterator __p, initializer_list __l) { __glibcxx_check_insert(__p); - return iterator(_Base::insert(__p.base(), __l), this); + return { _Base::insert(__p.base(), __l), this }; } #endif @@ -439,7 +439,7 @@ namespace __debug insert(const_iterator __position, size_type __n, const _Tp& __x) { __glibcxx_check_insert(__position); - return iterator(_Base::insert(__position.base(), __n, __x), this); + return { _Base::insert(__position.base(), __n, __x), this }; } #else void @@ -465,7 +465,7 @@ namespace __debug _Base::insert(__position.base(), __gnu_debug::__unsafe(__first), __gnu_debug::__unsafe(__last)), - this + this }; else return { _Base::insert(__position.base(), __first, __last), this }; @@ -521,15 +521,17 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 151. can't currently clear() empty container __glibcxx_check_erase_range(__first, __last); - for (_Base_const_iterator __victim = __first.base(); + for (__decltype(__first.base()) __victim = __first.base(); __victim != __last.base(); ++__victim) { - _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(), - _M_message(__gnu_debug::__msg_valid_range) - ._M_iterator(__first, "position") - ._M_iterator(__last, "last")); + _GLIBCXX_DEBUG_VERIFY( + __victim != __first._M_get_sequence()->_M_base().end(), + _M_message(__gnu_debug::__msg_valid_range) + ._M_iterator(__first, "position") + ._M_iterator(__last, "last")); this->_M_invalidate_if(_Equal(__victim)); } + return iterator(_Base::erase(__first.base(), __last.base()), this); } @@ -586,7 +588,7 @@ namespace __debug ._M_iterator(__i, "__i")); _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__x)), _M_message(__gnu_debug::__msg_splice_other) - ._M_iterator(__i, "__i")._M_sequence(__x, "__x")); + ._M_iterator(__i, "__i")._M_sequence(__x, "__x")); // _GLIBCXX_RESOLVE_LIB_DEFECTS // 250. splicing invalidates iterators @@ -620,19 +622,21 @@ namespace __debug // We used to perform the splice_alloc check: not anymore, redundant // after implementing the relevant bits of N1599. - for (_Base_const_iterator __tmp = __first.base(); + for (__decltype(__first.base()) __tmp = __first.base(); __tmp != __last.base(); ++__tmp) { - _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(), - _M_message(__gnu_debug::__msg_valid_range) - ._M_iterator(__first, "first") - ._M_iterator(__last, "last")); + _GLIBCXX_DEBUG_VERIFY( + __tmp != __first._M_get_sequence()->_M_base().end(), + _M_message(__gnu_debug::__msg_valid_range) + ._M_iterator(__first, "first") + ._M_iterator(__last, "last")); _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this || __tmp != __position.base(), _M_message(__gnu_debug::__msg_splice_overlap) ._M_iterator(__tmp, "position") ._M_iterator(__first, "first") ._M_iterator(__last, "last")); + // _GLIBCXX_RESOLVE_LIB_DEFECTS // 250. splicing invalidates iterators this->_M_transfer_from_if(__x, _Equal(__tmp));