From patchwork Fri Jan 3 21:04:56 2020 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: 1217431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516633-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="J/WRxTf+"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nHzvzmv5"; 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 47qHVP1HBZz9s29 for ; Sat, 4 Jan 2020 08:05:16 +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=bXdCS3ITvTgxSgXOw0wgDKBV0zcqgpFL0buloXaFKMH5SpVmdy pn03kSiDowZQ5xD6s35IcVX5AfWKsiph4z4rpLGcGCakp4zJwMzMwcdwN6+qGqFo QyEbHKZuw8uj/hZopG5TBV/4Hlgo2RKR0LfcVUPZnt+1D99KcWdehBj2A= 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=e/yUBfVZA+St9fH4wdPHXHiRUcY=; b=J/WRxTf+UDcyQBK13fOi eRoNqyBVy2YhZPHseAtvyQHWk9O+H9tk1xwAU6XaeMROMxaFocnRxKJB6pMp6D7v PJjGYRZseCb02LQn6ctrz9UoGYSTK8ZD27HxJxIBzOafgmtW4XlGSHdBizMLcm// /5f0AsX34twwfUKVfRt5XGY= Received: (qmail 2773 invoked by alias); 3 Jan 2020 21:05: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 2753 invoked by uid 89); 3 Jan 2020 21:05:02 -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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Tracking, qualify, Qualify X-HELO: mail-wm1-f50.google.com Received: from mail-wm1-f50.google.com (HELO mail-wm1-f50.google.com) (209.85.128.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Jan 2020 21:05:00 +0000 Received: by mail-wm1-f50.google.com with SMTP id a5so9464570wmb.0; Fri, 03 Jan 2020 13:05:00 -0800 (PST) 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=QPkUY+Lhq7Bo483MOWjhQnHoDx/q1NUqsc/hMBFulck=; b=nHzvzmv5AnYJaCqRVsuruUcWOhBf8TZDoVZF7yVeNe23iuvmC+xg+Q58NtPGKLYsen fneD2ma4CQOyIhsCfk/WDTQG0vz3f1unnW9pjff52dk/GHYx6Qn5e4Lnf/6A+DYuqgIq MGPKVLi2wmGEm0Nep84fgoKC2wI5O5pPPKBvvU0zNRhLAZR2oCNmD3jiLRlgLaLl4Q2X rTWpRRWaavlyFDXKV8i4MA2Oq9NHIKjVHn1gWQL09NiKYoTW4cVmioSwUD2q8zeQu/CU eEW/4df3hmTMJ79Fc7tiPpZYiwYkh/AcJMptvH2DvskJGpHHvkDgEB83qpq0hdfmtG/r SwRw== Received: from ?IPv6:2a01:e0a:1dc:b1c0:ddfa:53e7:1780:2ea2? ([2a01:e0a:1dc:b1c0:ddfa:53e7:1780:2ea2]) by smtp.googlemail.com with ESMTPSA id g21sm13394623wmh.17.2020.01.03.13.04.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jan 2020 13:04:57 -0800 (PST) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: [PATCH] libstdc++/92124 for associative containers Message-ID: <59741f68-288c-3111-5e59-5d0e229b68e6@gmail.com> Date: Fri, 3 Jan 2020 22:04:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 This is the patch to extend PR 92124 to the associative containers. As it is pretty simple I thought it could maybe go in now. I also think that the existing 92124 tests are not really testing what they should with the move assignment operators noexcept qualified, no ?     PR libstdc++/92124     * include/bits/stl_tree.h     (_Rb_tree<>::_M_move_assign(_Rb_tree&, false_type)): Replace     std::move_if_noexcept by std::move.     * testsuite/23_containers/deque/92124.cc     (X::operator==(X&&)): Qualify noexcept(false).     * testsuite/23_containers/forward_list/92124.cc: Likewise.     * testsuite/23_containers/list/92124.cc: Likewise.     * testsuite/23_containers/vector/92124.cc: Likewise.     * testsuite/23_containers/map/92124.cc: New.     * testsuite/23_containers/set/92124.cc: New. Tested under linux x86_64. François diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index 12ba3181dd9..9339011e872 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -1695,7 +1695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [&__roan](const value_type& __cval) { auto& __val = const_cast(__cval); - return __roan(std::move_if_noexcept(__val)); + return __roan(std::move(__val)); }; _M_root() = _M_copy(__x, __lbd); __x.clear(); diff --git a/libstdc++-v3/testsuite/23_containers/deque/92124.cc b/libstdc++-v3/testsuite/23_containers/deque/92124.cc index 0bdfcb70dcf..ea16d415a49 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/92124.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/92124.cc @@ -30,7 +30,7 @@ struct X { // Tracking calls to assignment functions X& operator=(const X&) { throw 1; } - X& operator=(X&&) noexcept(true) { return *this; } + X& operator=(X&&) noexcept(false) { return *this; } }; void diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc index 3e1b7ab3421..4d037f3a08f 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc @@ -30,7 +30,7 @@ struct X { // Tracking calls to assignment functions X& operator=(const X&) { throw 1; } - X& operator=(X&&) noexcept(true) { return *this; } + X& operator=(X&&) noexcept(false) { return *this; } }; void diff --git a/libstdc++-v3/testsuite/23_containers/list/92124.cc b/libstdc++-v3/testsuite/23_containers/list/92124.cc index f9f2ed2e76f..49b74cab7e5 100644 --- a/libstdc++-v3/testsuite/23_containers/list/92124.cc +++ b/libstdc++-v3/testsuite/23_containers/list/92124.cc @@ -30,7 +30,7 @@ struct X { // Tracking calls to assignment functions X& operator=(const X&) { throw 1; } - X& operator=(X&&) noexcept(true) { return *this; } + X& operator=(X&&) noexcept(false) { return *this; } }; void diff --git a/libstdc++-v3/testsuite/23_containers/map/92124.cc b/libstdc++-v3/testsuite/23_containers/map/92124.cc new file mode 100644 index 00000000000..177c9d7abe9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/92124.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2020 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-do run { target c++11 } } + +#include +#include + +struct X +{ + X() = default; + X(const X&) + { if (Throw) throw 1; } + + // Move constructor might throw + X(X&&) noexcept(false) {} + + // Tracking calls to assignment functions + X& operator=(const X&) { throw 1; } + + X& operator=(X&&) noexcept(false) { return *this; } + + static bool Throw; +}; + +bool X::Throw = false; + +void +test01() +{ + using A = __gnu_test::propagating_allocator, false>; + A a1(1), a2(2); + std::map, A> + m1({ { 1, X() } }, a1), + m2({ { 2, X() } }, a2); + X::Throw = true; + m1 = std::move(m2); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/92124.cc b/libstdc++-v3/testsuite/23_containers/set/92124.cc new file mode 100644 index 00000000000..95a2e9ce518 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/92124.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2020 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-do run { target c++11 } } + +#include +#include + +struct X +{ + X(int i) noexcept(true) : _i(i) { } + X(const X& x) noexcept(false) + { + if (Throw) throw 0; + _i = x._i; + } + + // Move constructor might throw + X(X&& x) noexcept(false) + { + _i = x._i; + x._i = -x._i; + } + + // Tracking calls to assignment functions + X& operator=(const X&) { throw 1; } + + X& operator=(X&& x) noexcept(false) + { + _i = x._i; + x._i = -x._i; + return *this; + } + + bool + operator < (const X& x) const + { return _i < x._i; } + + int _i; + static bool Throw; +}; + +bool X::Throw = false; + +void +test01() +{ + using A = __gnu_test::propagating_allocator; + A a1(1), a2(2); + std::set, A> s1({ X(1) }, a1), s2({ X(2) }, a2); + X::Throw = true; + s1 = std::move(s2); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/92124.cc b/libstdc++-v3/testsuite/23_containers/vector/92124.cc index b5bf73e07de..cd201412e20 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/92124.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/92124.cc @@ -30,7 +30,7 @@ struct X { // Tracking calls to assignment functions X& operator=(const X&) { throw 1; } - X& operator=(X&&) noexcept(true) { return *this; } + X& operator=(X&&) noexcept(false) { return *this; } }; void