From: Paolo Carlini Date: Sun, 28 Sep 2008 15:47:45 +0000 (+0000) Subject: unique_ptr.h (unique_ptr<_Tp[]>::template void reset(U)): Add as deleted... X-Git-Tag: releases/gcc-4.4.0~2234 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d5f7a16ebc7931c798d266a2b172c856ef26531;p=thirdparty%2Fgcc.git unique_ptr.h (unique_ptr<_Tp[]>::template void reset(U)): Add as deleted function, per DR 821 [Ready]. 2008-09-28 Paolo Carlini * include/bits/unique_ptr.h (unique_ptr<_Tp[]>::template void reset(U)): Add as deleted function, per DR 821 [Ready]. * include/bits/unique_ptr.h: Prefer everywhere deleted to private member function declarations; minor formatting tweaks. * testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: New. * testsuite/20_util/unique_ptr/assign/assign.cc: Adjust DejaGNU directives. From-SVN: r140737 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 74ec22612727..3448d906d952 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2008-09-28 Paolo Carlini + + * include/bits/unique_ptr.h (unique_ptr<_Tp[]>::template + void reset(U)): Add as deleted function, per DR 821 [Ready]. + * include/bits/unique_ptr.h: Prefer everywhere deleted to private + member function declarations; minor formatting tweaks. + * testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: New. + * testsuite/20_util/unique_ptr/assign/assign.cc: Adjust DejaGNU + directives. + 2008-09-28 Chris Fairles * include/std/mutex (try_lock): Implement generic try_lock. diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index ead0acf9515b..3123a79ccaec 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -84,15 +84,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template > class unique_ptr { - typedef _Tp* pointer; - typedef unique_ptr<_Tp, _Tp_Deleter> __this_type; - typedef std::tuple __tuple_type; - typedef __tuple_type __this_type::* __unspecified_bool_type; - typedef pointer __this_type::* __unspecified_pointer_type; + typedef unique_ptr<_Tp, _Tp_Deleter> __this_type; + typedef std::tuple<_Tp*, _Tp_Deleter> __tuple_type; + typedef __tuple_type __this_type::* __unspecified_bool_type; + typedef _Tp* __this_type::* __unspecified_pointer_type; public: - typedef _Tp element_type; - typedef _Tp_Deleter deleter_type; + typedef _Tp* pointer; + typedef _Tp element_type; + typedef _Tp_Deleter deleter_type; // constructors unique_ptr() @@ -195,7 +195,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } void - reset(pointer __p = 0) + reset(pointer __p = pointer()) { if (__p != get()) { @@ -206,23 +206,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void swap(unique_ptr&& __u) - { using std::swap; + { + using std::swap; swap(_M_t, __u._M_t); } - private: // disable copy from lvalue - unique_ptr(const unique_ptr&); + unique_ptr(const unique_ptr&) = delete; template - unique_ptr(const unique_ptr<_Up, _Up_Deleter>&); - - // disable assignment from lvalue - unique_ptr& operator=(const unique_ptr&); + unique_ptr(const unique_ptr<_Up, _Up_Deleter>&) = delete; + + unique_ptr& operator=(const unique_ptr&) = delete; template - unique_ptr& operator=(const unique_ptr<_Up, _Up_Deleter>&); - + unique_ptr& operator=(const unique_ptr<_Up, _Up_Deleter>&) = delete; + private: __tuple_type _M_t; }; @@ -234,15 +233,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template class unique_ptr<_Tp[], _Tp_Deleter> { - typedef _Tp* pointer; - typedef unique_ptr<_Tp[], _Tp_Deleter> __this_type; - typedef std::tuple __tuple_type; - typedef __tuple_type __this_type::* __unspecified_bool_type; - typedef pointer __this_type::* __unspecified_pointer_type; + typedef unique_ptr<_Tp[], _Tp_Deleter> __this_type; + typedef std::tuple<_Tp*, _Tp_Deleter> __tuple_type; + typedef __tuple_type __this_type::* __unspecified_bool_type; + typedef _Tp* __this_type::* __unspecified_pointer_type; + public: - typedef _Tp element_type; - typedef _Tp_Deleter deleter_type; - + typedef _Tp* pointer; + typedef _Tp element_type; + typedef _Tp_Deleter deleter_type; + // constructors unique_ptr() : _M_t(pointer(), deleter_type()) @@ -338,7 +338,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } void - reset(pointer __p = 0) + reset(pointer __p = pointer()) { if (__p != get()) { @@ -347,6 +347,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } } + // DR 821. + template + void reset(_Up) = delete; + void swap(unique_ptr&& __u) { @@ -354,66 +358,62 @@ _GLIBCXX_BEGIN_NAMESPACE(std) swap(_M_t, __u._M_t); } - private: // disable copy from lvalue - unique_ptr(const unique_ptr&); - unique_ptr& operator=(const unique_ptr&); + unique_ptr(const unique_ptr&) = delete; + unique_ptr& operator=(const unique_ptr&) = delete; // disable construction from convertible pointer types // (N2315 - 20.6.5.3.1) - template unique_ptr(_Up*, - typename std::conditional::value, - deleter_type, const deleter_type&>::type, - typename std::enable_if::value>::type* = 0); - - template unique_ptr(_Up*, - typename std::remove_reference::type&&, - typename std::enable_if::value>::type* = 0); - - template explicit unique_ptr(_Up*, - typename std::enable_if::value>::type* = 0); - - // disable reset with convertible pointer types (N2315 - 20.6.5.3.3) template - typename std::enable_if::value>::type reset(_Up*); - + unique_ptr(_Up*, typename + std::conditional::value, + deleter_type, const deleter_type&>::type, + typename std::enable_if::value>::type* = 0) = delete; + + template + unique_ptr(_Up*, typename std::remove_reference::type&&, + typename std::enable_if::value>::type* = 0) = delete; + + template + explicit + unique_ptr(_Up*, typename std::enable_if::value>::type* = 0) = delete; + private: __tuple_type _M_t; }; template inline void - swap(unique_ptr<_Tp, _Tp_Deleter>& __x, - unique_ptr<_Tp, _Tp_Deleter>& __y) + swap(unique_ptr<_Tp, _Tp_Deleter>& __x, + unique_ptr<_Tp, _Tp_Deleter>& __y) { __x.swap(__y); } template inline void - swap(unique_ptr<_Tp, _Tp_Deleter>&& __x, + swap(unique_ptr<_Tp, _Tp_Deleter>&& __x, unique_ptr<_Tp, _Tp_Deleter>& __y) { __x.swap(__y); } template inline void - swap(unique_ptr<_Tp, _Tp_Deleter>& __x, + swap(unique_ptr<_Tp, _Tp_Deleter>& __x, unique_ptr<_Tp, _Tp_Deleter>&& __y) { __x.swap(__y); } template inline bool - operator==(const unique_ptr<_Tp, _Tp_Deleter>& __x, + operator==(const unique_ptr<_Tp, _Tp_Deleter>& __x, const unique_ptr<_Up, _Up_Deleter>& __y) { return __x.get() == __y.get(); } template inline bool - operator!=(const unique_ptr<_Tp, _Tp_Deleter>& __x, + operator!=(const unique_ptr<_Tp, _Tp_Deleter>& __x, const unique_ptr<_Up, _Up_Deleter>& __y) { return !(__x.get() == __y.get()); } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc index 559ade35c1a5..3ccc8701a0cd 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc @@ -40,13 +40,20 @@ void test02() { std::unique_ptr p1(new int(420)); - std::unique_ptr p2 = p1; // { dg-error "within this context" } + std::unique_ptr p2 = p1; } void test03() { std::unique_ptr p1(new int[3]); - std::unique_ptr p2 = p1; // { dg-error "within this context" } + std::unique_ptr p2 = p1; } -// { dg-excess-errors "is private" } + +// { dg-error "used here" "" { target *-*-* } 43 } +// { dg-error "no matching" "" { target *-*-* } 49 } +// { dg-error "used here" "" { target *-*-* } 50 } +// { dg-error "candidates are" "" { target *-*-* } 215 } +// { dg-error "deleted function" "" { target *-*-* } 215 } +// { dg-error "deleted function" "" { target *-*-* } 362 } +// { dg-excess-errors "note" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc new file mode 100644 index 000000000000..37fcb6c9ed93 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include + +struct A +{ +}; + +struct B : A +{ + virtual ~B() { } +}; + +void test01() +{ + std::unique_ptr up; + up.reset(new A[3]); +} + +// { dg-error "used here" "" { target *-*-* } 36 } +// { dg-error "deleted function" "" { target *-*-* } 352 }