From patchwork Thu Oct 11 20:46:08 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: 982716 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-487391-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="lQoE0siE"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FHk2Bxq3"; 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 42WNKw18vZz9sBZ for ; Fri, 12 Oct 2018 07:46:26 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=SU2aBi+YHxvNbABGnB/o63wYfstz9v45uHCyV2o5Y+KdKXE0TF XOh4NZUp1yN+G8mHiUzlSF1aL5SCofyUx6oHWSl2O+P4OoLA7yBRwXhExB4V3op8 k2RtdrL6//2cjewFBgRNjJZGdoHHe4P5N7jRoPIpM4busKfP6RftXIcL4= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=p5bLLlnA9l5OdnCM37MYyUTt0Tk=; b=lQoE0siEmOTJZ1NHOLEv VqELcoAOn0zq4e2Qn2CpoVFXlbcTl2ArsFCbWwVmSJZehlf4+HwO+E6Oho4zmkle 8zBBxUFBSWF0dmSY2M3XY7NJXO6NPb2E9VkCPIwzvFBj4W9Bp4NwTUxi/DlxgJSj bmIQXHO+lwdv3yevF7eB80U= Received: (qmail 80101 invoked by alias); 11 Oct 2018 20:46:18 -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 80012 invoked by uid 89); 11 Oct 2018 20:46:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, 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=HX-Received:sk:g17-v6m, cend, cbegin X-HELO: mail-wr1-f48.google.com Received: from mail-wr1-f48.google.com (HELO mail-wr1-f48.google.com) (209.85.221.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Oct 2018 20:46:12 +0000 Received: by mail-wr1-f48.google.com with SMTP id l6-v6so10724624wrt.1; Thu, 11 Oct 2018 13:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=GmfEcL65hXfzYFUPXQwN3DD4JK7tN526ic163or59YE=; b=FHk2Bxq3lGTqvPelWPvAX3MyTxvlvz5bn2fCzVg5XGMreL87fNRuO+J6j8ewovBbo+ +ycXPAKyAmcr0eYXszAezDSQlUSavuprV1+Ukfz9eOa2+00GN3Gloc9YAXa0NV0twLjj 95/HTQKk3iCCZk2PYghKp9nqJ8OOXo/bvIATmECpIn+5E1jpCyH9f8EXzJWGbXWKbe24 ZyZrNv3RAocPwuspnfbdJRgYdNHpEXBpqATQgRftRpx7j8Qf7nmaLydvayaPLmF1tNVP 9pII4eeZXTYJGSlx9jgyXWdzkq3qkjYvuuDKA8zNUN6pVA05mrz+RLF1RkGEIU3h+RzK Vyig== Received: from [192.168.0.22] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id k7-v6sm843420wmf.22.2018.10.11.13.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 13:46:09 -0700 (PDT) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: Use C++11 direct init in __debug::forward_list Message-ID: Date: Thu, 11 Oct 2018 22:46:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 This patch makes extensive use of C++11 direct init in __debug::forward_list. Doing so I also try to detect useless creation of safe iterators in debug implementation. In __debug::forward_list there are severals but I wonder if it is worth fixing those. Most of them are like this:       void       splice_after(const_iterator __pos, forward_list& __list)       { splice_after(__pos, std::move(__list)); } __pos is copied. Do you think I shouldn't care, gcc will optimize it ? I wonder if it would be ok in debug implementation to use this kind of signature: void splice_after(const const_iterator& __pos, forward_list& __list) Iterator taken as rvalue reference ? I guess it is not Standard conformant so not correct but maybe I could add a private _M_splice_after with this signature.     * include/debug/forward_list     (forward_list<>::before_begin()): Use C++11 direct initialization.     (forward_list<>::begin()): Likewise.     (forward_list<>::end()): Likewise.     (forward_list<>::cbefore_begin()): Likewise.     (forward_list<>::cbegin()): Likewise.     (forward_list<>::cend()): Likewise.     (forward_list<>::emplace_after<>(const_iterator, _Args&&...)): Likewise.     (forward_list<>::insert_after(const_iterator, const _Tp&)): Likewise.     (forward_list<>::insert_after(const_iterator, _Tp&&)): Likewise.     (forward_list<>::insert_after(const_iterator, size_type, const _Tp&)):     Likewise.     (forward_list<>::insert_after(const_iterator, initializer_list<>)):     Likewise.     (forward_list<>::erase_after(const_iterator)): Likewise.     (forward_list<>::erase_after(const_iterator, const_iterator)): Likewise     and ensure consistent iterator comparison. Tested under Linux x86_64, Debug mode and committed. François diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list index e542447badd..c9744eda55a 100644 --- a/libstdc++-v3/include/debug/forward_list +++ b/libstdc++-v3/include/debug/forward_list @@ -316,39 +316,39 @@ namespace __debug iterator before_begin() noexcept - { return iterator(_Base::before_begin(), this); } + { return { _Base::before_begin(), this }; } const_iterator before_begin() const noexcept - { return const_iterator(_Base::before_begin(), this); } + { return { _Base::before_begin(), this }; } iterator begin() noexcept - { return iterator(_Base::begin(), this); } + { return { _Base::begin(), this }; } const_iterator begin() const noexcept - { return const_iterator(_Base::begin(), this); } + { return { _Base::begin(), this }; } iterator end() noexcept - { return iterator(_Base::end(), this); } + { return { _Base::end(), this }; } const_iterator end() const noexcept - { return const_iterator(_Base::end(), this); } + { return { _Base::end(), this }; } const_iterator cbegin() const noexcept - { return const_iterator(_Base::cbegin(), this); } + { return { _Base::cbegin(), this }; } const_iterator cbefore_begin() const noexcept - { return const_iterator(_Base::cbefore_begin(), this); } + { return { _Base::cbefore_begin(), this }; } const_iterator cend() const noexcept - { return const_iterator(_Base::cend(), this); } + { return { _Base::cend(), this }; } using _Base::empty; using _Base::max_size; @@ -388,32 +388,30 @@ namespace __debug emplace_after(const_iterator __pos, _Args&&... __args) { __glibcxx_check_insert_after(__pos); - return iterator(_Base::emplace_after(__pos.base(), + return { _Base::emplace_after(__pos.base(), std::forward<_Args>(__args)...), - this); + this }; } iterator insert_after(const_iterator __pos, const _Tp& __val) { __glibcxx_check_insert_after(__pos); - return iterator(_Base::insert_after(__pos.base(), __val), this); + return { _Base::insert_after(__pos.base(), __val), this }; } iterator insert_after(const_iterator __pos, _Tp&& __val) { __glibcxx_check_insert_after(__pos); - return iterator(_Base::insert_after(__pos.base(), std::move(__val)), - this); + return { _Base::insert_after(__pos.base(), std::move(__val)), this }; } iterator insert_after(const_iterator __pos, size_type __n, const _Tp& __val) { __glibcxx_check_insert_after(__pos); - return iterator(_Base::insert_after(__pos.base(), __n, __val), - this); + return { _Base::insert_after(__pos.base(), __n, __val), this }; } template __il) { __glibcxx_check_insert_after(__pos); - return iterator(_Base::insert_after(__pos.base(), __il), this); + return { _Base::insert_after(__pos.base(), __il), this }; } private: @@ -458,7 +456,7 @@ namespace __debug erase_after(const_iterator __pos) { __glibcxx_check_erase_after(__pos); - return iterator(_M_erase_after(__pos.base()), this); + return { _M_erase_after(__pos.base()), this }; } iterator @@ -468,7 +466,7 @@ namespace __debug for (_Base_const_iterator __victim = std::next(__pos.base()); __victim != __last.base(); ++__victim) { - _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(), + _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(), _M_message(__gnu_debug::__msg_valid_range2) ._M_sequence(*this, "this") ._M_iterator(__pos, "pos") @@ -476,7 +474,8 @@ namespace __debug this->_M_invalidate_if([__victim](_Base_const_iterator __it) { return __it == __victim; }); } - return iterator(_Base::erase_after(__pos.base(), __last.base()), this); + + return { _Base::erase_after(__pos.base(), __last.base()), this }; } void