From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47265 invoked by alias); 13 May 2015 16:43:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 47244 invoked by uid 89); 13 May 2015 16:43:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD,UNWANTED_LANGUAGE_BODY 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; Wed, 13 May 2015 16:43:06 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4DGh57T024463 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2015 12:43:05 -0400 Received: from localhost (ovpn-116-36.ams2.redhat.com [10.36.116.36]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4DGh45i007205; Wed, 13 May 2015 12:43:04 -0400 Date: Wed, 13 May 2015 16:46:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] Constructing std::shared_ptr from an empty std::unique_ptr Message-ID: <20150513164229.GN30202@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cDtQGJ/EJIRf/Cpq" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-05/txt/msg01244.txt.bz2 --cDtQGJ/EJIRf/Cpq Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 151 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2415 Voted in to the WP in Lenexa. Tested powerpc64le-linux, committed to trunk. --cDtQGJ/EJIRf/Cpq Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 3258 commit 87937e036ae87944f7ac2b26d8ae17fe81525c4f Author: Jonathan Wakely Date: Wed May 13 15:54:45 2015 +0100 * include/bits/shared_ptr_base.h (__shared_count(unique_ptr&&)): Check for nullptr (LWG 2415). * testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc: Test construction from empty unique_ptr. * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error. * testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 8c3af12..081df87 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -632,6 +632,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit __shared_count(std::unique_ptr<_Tp, _Del>&& __r) : _M_pi(0) { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2415. Inconsistency between unique_ptr and shared_ptr + if (__r.get() == nullptr) + return; + using _Ptr = typename unique_ptr<_Tp, _Del>::pointer; using _Del2 = typename conditional::value, reference_wrapper::type>, diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc index 97cc139..6255522 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc @@ -32,7 +32,7 @@ void test01() { X* px = 0; std::shared_ptr p1(px); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 886 } + // { dg-error "incomplete" "" { target *-*-* } 891 } std::shared_ptr p9(ap()); // { dg-error "here" } // { dg-error "incomplete" "" { target *-*-* } 307 } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc index 67bf577..e010977 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc @@ -34,7 +34,7 @@ int D::count = 0; // 20.7.12.2.1 shared_ptr constructors [util.smartptr.shared.const] // Construction from unique_ptr -int +void test01() { bool test __attribute__((unused)) = true; @@ -47,13 +47,25 @@ test01() VERIFY( sp.use_count() == 1 ); } VERIFY( D::count == 1 ); +} - return 0; +void +test02() +{ + bool test __attribute__((unused)) = true; + + D::count = 0; + std::unique_ptr up; + { + std::shared_ptr sp = std::move(up); + } + VERIFY( D::count == 0 ); // LWG 2415 } int main() { test01(); + test02(); return 0; } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc index 2afcd8b..3f6c4ae 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc @@ -25,5 +25,5 @@ void test01() { std::shared_ptr p((void*)nullptr); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 885 } + // { dg-error "incomplete" "" { target *-*-* } 890 } } --cDtQGJ/EJIRf/Cpq--