From patchwork Tue Aug 10 10:13:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 61371 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]) by ozlabs.org (Postfix) with SMTP id 5C10FB710F for ; Tue, 10 Aug 2010 20:13:56 +1000 (EST) Received: (qmail 32352 invoked by alias); 10 Aug 2010 10:13:46 -0000 Received: (qmail 32304 invoked by uid 22791); 10 Aug 2010 10:13:39 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp4.tin.it (HELO vsmtp4.tin.it) (212.216.176.224) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Aug 2010 10:13:30 +0000 Received: from [192.168.0.4] (79.52.193.127) by vsmtp4.tin.it (8.5.113) id 4BCE3CBE094B0717; Tue, 10 Aug 2010 12:13:27 +0200 Message-ID: <4C612647.6040901@oracle.com> Date: Tue, 10 Aug 2010 12:13:27 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Thunderbird/3.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Add unique_ptr(auto_ptr<_Up>&&) + contraints X-IsSubscribed: yes 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 Hi, I checked our smart pointers vs US 108 and went add adding the unique_ptr constructor from auto_ptr which we were missing. I also added some missing constraining to the member functions of those classes. Tested x86_64-linux, committed to mainline. Paolo. ///////////////////////// 2010-08-10 Paolo Carlini * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Avoid -Wall warnings. * include/bits/shared_ptr.h (shared_ptr<>::shared_ptr (const shared_ptr<>&), shared_ptr(shared_ptr<>&&), weak_ptr<>:: weak_ptr(const weak_ptr<>&), weak_ptr(const shared_ptr<>&)): Constrain appropriately via std::is_convertible, etc. * include/bits/shared_ptr_base.h: Likewise. * include/bits/unique_ptr.h (default_delete<>:: default_delete(const default_delete<>&), unique_ptr<>::unique_ptr(unique_ptr<>&&), operator=(unique_ptr<>&&)): Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line numbers. * testsuite/20_util/shared_ptr/cons/43820.cc: Likewise. * include/bits/unique_ptr.h (unique_ptr<>::unique_ptr(auto_ptr<>&&)): Add. * include/std/memory: Adjust includes order. * testsuite/20_util/unique_ptr/cons/auto_ptr.cc: New. * testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc: Likewise. * testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc: Minor tweaks. Index: include/std/memory =================================================================== --- include/std/memory (revision 163048) +++ include/std/memory (working copy) @@ -1,6 +1,7 @@ // -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +// 2009, 2010 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -81,10 +82,10 @@ # include # include # include -# include # if _GLIBCXX_DEPRECATED # include # endif +# include # if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # include # else Index: include/bits/shared_ptr.h =================================================================== --- include/bits/shared_ptr.h (revision 163048) +++ include/bits/shared_ptr.h (working copy) @@ -206,8 +206,10 @@ * @param __r A %shared_ptr. * @post get() == __r.get() && use_count() == __r.use_count() */ - template - shared_ptr(const shared_ptr<_Tp1>& __r) : __shared_ptr<_Tp>(__r) { } + template::value>::type> + shared_ptr(const shared_ptr<_Tp1>& __r) + : __shared_ptr<_Tp>(__r) { } /** * @brief Move-constructs a %shared_ptr instance from @a __r. @@ -222,7 +224,8 @@ * @param __r A %shared_ptr rvalue. * @post *this contains the old value of @a __r, @a __r is empty. */ - template + template::value>::type> shared_ptr(shared_ptr<_Tp1>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } @@ -366,11 +369,13 @@ public: weak_ptr() : __weak_ptr<_Tp>() { } - template + template::value>::type> weak_ptr(const weak_ptr<_Tp1>& __r) : __weak_ptr<_Tp>(__r) { } - template + template::value>::type> weak_ptr(const shared_ptr<_Tp1>& __r) : __weak_ptr<_Tp>(__r) { } Index: include/bits/unique_ptr.h =================================================================== --- include/bits/unique_ptr.h (revision 163048) +++ include/bits/unique_ptr.h (working copy) @@ -49,7 +49,8 @@ { default_delete() { } - template + template::value>::type> default_delete(const default_delete<_Up>&) { } void @@ -133,14 +134,32 @@ unique_ptr(unique_ptr&& __u) : _M_t(__u.release(), std::forward(__u.get_deleter())) { } - template + template::pointer, + pointer>::value + && !std::is_array<_Up>::value + && ((std::is_reference<_Tp_Deleter>::value + && std::is_same<_Up_Deleter, _Tp_Deleter>::value) + || (!std::is_reference<_Tp_Deleter>::value + && std::is_convertible<_Up_Deleter, _Tp_Deleter>::value))> + ::type> unique_ptr(unique_ptr<_Up, _Up_Deleter>&& __u) : _M_t(__u.release(), std::forward(__u.get_deleter())) { } +#if _GLIBCXX_DEPRECATED + template::value + && std::is_same<_Tp_Deleter, + default_delete<_Tp>>::value>::type> + unique_ptr(auto_ptr<_Up>&& __u) + : _M_t(__u.release(), deleter_type()) { } +#endif + // Destructor. ~unique_ptr() { reset(); } - + // Assignment. unique_ptr& operator=(unique_ptr&& __u) @@ -150,7 +169,11 @@ return *this; } - template + template::pointer, + pointer>::value + && !std::is_array<_Up>::value>::type> unique_ptr& operator=(unique_ptr<_Up, _Up_Deleter>&& __u) { Index: include/bits/shared_ptr_base.h =================================================================== --- include/bits/shared_ptr_base.h (revision 163048) +++ include/bits/shared_ptr_base.h (working copy) @@ -601,7 +601,8 @@ // generated copy constructor, assignment, destructor are fine. - template + template::value>::type> __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } @@ -613,7 +614,8 @@ __r._M_ptr = 0; } - template + template::value>::type> __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r) : _M_ptr(__r._M_ptr), _M_refcount() // never throws { @@ -965,7 +967,8 @@ // // It is not possible to avoid spurious access violations since // in multithreaded programs __r._M_ptr may be invalidated at any point. - template + template::value>::type> __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) : _M_refcount(__r._M_refcount) // never throws { @@ -973,7 +976,8 @@ _M_ptr = __r.lock().get(); } - template + template::value>::type> __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } Index: testsuite/20_util/unique_ptr/cons/auto_ptr.cc =================================================================== --- testsuite/20_util/unique_ptr/cons/auto_ptr.cc (revision 0) +++ testsuite/20_util/unique_ptr/cons/auto_ptr.cc (revision 0) @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// 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 +// . + +// 20.9.10 Class template unique_ptr [unique.ptr] + +#include +#include + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from auto_ptr +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::auto_ptr a(new A); + std::unique_ptr a2(std::move(a)); + VERIFY( a.get() == nullptr ); + VERIFY( a2.get() != 0 ); +} + +int +main() +{ + test01(); + return 0; +} Index: testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc =================================================================== --- testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc (revision 0) +++ testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc (revision 0) @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// 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 +// . + +// 20.9.10 Class template unique_ptr [unique.ptr] + +#include + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from const auto_ptr +void +test01() +{ + const std::auto_ptr a(new A); + std::unique_ptr a2(std::move(a)); // { dg-error "no match" } +} +// { dg-excess-errors "candidates are" } Index: testsuite/20_util/ratio/cons/cons_overflow_neg.cc =================================================================== --- testsuite/20_util/ratio/cons/cons_overflow_neg.cc (revision 163048) +++ testsuite/20_util/ratio/cons/cons_overflow_neg.cc (working copy) @@ -2,7 +2,7 @@ // { dg-options "-std=gnu++0x" } // { dg-require-cstdint "" } -// Copyright (C) 2008, 2009 Free Software Foundation +// Copyright (C) 2008, 2009, 2010 Free Software Foundation // // 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 @@ -24,26 +24,26 @@ void test01() { - std::ratio r1; - std::ratio<-INTMAX_MAX, INTMAX_MAX> r2; + std::ratio r1 __attribute__((unused)); + std::ratio<-INTMAX_MAX, INTMAX_MAX> r2 __attribute__((unused)); } void test02() { - std::ratio r1; + std::ratio r1 __attribute__((unused)); } void test03() { - std::ratio<1, INTMAX_MIN> r1; + std::ratio<1, INTMAX_MIN> r1 __attribute__((unused)); } void test04() { - std::ratio<1,0> r1; + std::ratio<1,0> r1 __attribute__((unused)); } // { dg-error "instantiated from here" "" { target *-*-* } 34 } Index: testsuite/20_util/shared_ptr/cons/43820.cc =================================================================== --- testsuite/20_util/shared_ptr/cons/43820.cc (revision 163049) +++ testsuite/20_util/shared_ptr/cons/43820.cc (working copy) @@ -35,6 +35,6 @@ // { dg-error "incomplete" "" { target *-*-* } 566 } std::shared_ptr p9(ap()); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 657 } + // { dg-error "incomplete" "" { target *-*-* } 659 } } Index: testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc =================================================================== --- testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc (revision 163049) +++ testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc (working copy) @@ -21,28 +21,16 @@ // 20.6.6.2 Template class shared_ptr [util.smartptr.shared] #include -#include struct A { }; // 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.const] // Construction from const auto_ptr -int +void test01() { - bool test __attribute__((unused)) = true; - const std::auto_ptr a; std::shared_ptr p(std::move(a)); // { dg-error "no match" } - - return 0; } - -int -main() -{ - test01(); - return 0; -} // { dg-excess-errors "candidates are" } Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 163049) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -41,9 +41,9 @@ return 0; } -// { dg-warning "note" "" { target *-*-* } 324 } -// { dg-warning "note" "" { target *-*-* } 423 } -// { dg-warning "note" "" { target *-*-* } 862 } +// { dg-warning "note" "" { target *-*-* } 327 } +// { dg-warning "note" "" { target *-*-* } 446 } +// { dg-warning "note" "" { target *-*-* } 864 } // { dg-warning "note" "" { target *-*-* } 580 } // { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 340 }