From patchwork Thu Sep 25 12:14:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 393322 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 1114014017F for ; Thu, 25 Sep 2014 22:14:31 +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:subject:message-id:mime-version:content-type; q=dns; s= default; b=slX+cYzWDMsAEX90kiVHXRvbBm0rlxtt20NJRzW1hD4Ntu/K8D8nh ndw9IGBaIln9XNOU6UJWDOfTyc/sIzps21CLFifyX+5gtmzX2xhVdMJbYkZaqPpm yq47NClB7K+1VvGFlsusYaF2FJiLa5FcEqQcZjBH5F+wuKFvgytROk= 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:subject:message-id:mime-version:content-type; s= default; bh=0LTiuBKyZ6U6PbXZrFwesHT0+UE=; b=tLBwNep7JG4Z3QpZc3Sb eMXNwBiUQBfNP+HFKN4i47sGT+YDQJc3LHNINcdDUuUuvIEmZ+Y5p+e1O4KM3GAA KBgP3VeBHFR/pLH5vhmfDjCx6qt234m5Akgo2s1ZXG2kvbHtia8WeDZvBHwp2W0H r6bl1wQ1USyYz6mjRoMv0U4= Received: (qmail 17813 invoked by alias); 25 Sep 2014 12:14:25 -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 17796 invoked by uid 89); 25 Sep 2014 12:14:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 25 Sep 2014 12:14:23 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8PCEMhB002036 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 25 Sep 2014 08:14:22 -0400 Received: from localhost (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8PCELe2028947; Thu, 25 Sep 2014 08:14:21 -0400 Date: Thu, 25 Sep 2014 13:14:20 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] std::vector::assign should not call std::vector::swap Message-ID: <20140925121420.GE2669@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) With C++11 allocator semantics the swap() member might also replace the allocator, which is only allowed in specific circumstances. Even though the worst that could happen is we replace the allocator with an equal one, we should avoid using swap and use the internal _M_swap_data function instead. I'm not adding a test, as I don't think this is likely to regress and to do it properly we'd need to test every member function and ensure only the correct ones replace the allocator. I searched, and we don't use swap() inappropriately elsewhere in std::vector. Tested x86_64-linux, committed to trunk. commit 6a3d7b12c8879a0431e8aa9ffb521f18063debc6 Author: Jonathan Wakely Date: Thu Sep 25 13:03:40 2014 +0100 * include/bits/vector.tcc (vector::_M_fill_assign): Use _M_swap_data. diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 5c3dfae..4eacec3 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -228,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER if (__n > capacity()) { vector __tmp(__n, __val, _M_get_Tp_allocator()); - __tmp.swap(*this); + __tmp._M_impl._M_swap_data(this->_M_impl); } else if (__n > size()) {