aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2008-09-28 15:47:45 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2008-09-28 15:47:45 +0000
commit0d5f7a16ebc7931c798d266a2b172c856ef26531 (patch)
tree2e1b13331593af53f2952a7f8e50a3a09fedc285
parent58760a81d720022370380a3607548e7d48e9ea83 (diff)
downloadgcc-0d5f7a16ebc7931c798d266a2b172c856ef26531.zip
gcc-0d5f7a16ebc7931c798d266a2b172c856ef26531.tar.gz
gcc-0d5f7a16ebc7931c798d266a2b172c856ef26531.tar.bz2
unique_ptr.h (unique_ptr<_Tp[]>::template<typename U> void reset(U)): Add as deleted function, per DR 821 [Ready].
2008-09-28 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/unique_ptr.h (unique_ptr<_Tp[]>::template<typename U> 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
-rw-r--r--libstdc++-v3/ChangeLog10
-rw-r--r--libstdc++-v3/include/bits/unique_ptr.h108
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc13
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc40
4 files changed, 114 insertions, 57 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 74ec226..3448d90 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2008-09-28 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/unique_ptr.h (unique_ptr<_Tp[]>::template<typename U>
+ 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 <cfairles@gcc.gnu.org>
* 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 ead0acf..3123a79 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 <typename _Tp, typename _Tp_Deleter = default_delete<_Tp> >
class unique_ptr
{
- typedef _Tp* pointer;
- typedef unique_ptr<_Tp, _Tp_Deleter> __this_type;
- typedef std::tuple<pointer, _Tp_Deleter> __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<typename _Up, typename _Up_Deleter>
- 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<typename _Up, typename _Up_Deleter>
- 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<typename _Tp, typename _Tp_Deleter>
class unique_ptr<_Tp[], _Tp_Deleter>
{
- typedef _Tp* pointer;
- typedef unique_ptr<_Tp[], _Tp_Deleter> __this_type;
- typedef std::tuple<pointer, _Tp_Deleter> __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<typename _Up>
+ 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<typename _Up> unique_ptr(_Up*,
- typename std::conditional<std::is_reference<deleter_type>::value,
- deleter_type, const deleter_type&>::type,
- typename std::enable_if<std::is_convertible<_Up*,
- pointer>::value>::type* = 0);
-
- template<typename _Up> unique_ptr(_Up*,
- typename std::remove_reference<deleter_type>::type&&,
- typename std::enable_if<std::is_convertible<_Up*,
- pointer>::value>::type* = 0);
-
- template<typename _Up> explicit unique_ptr(_Up*,
- typename std::enable_if<std::is_convertible<_Up*,
- pointer>::value>::type* = 0);
-
- // disable reset with convertible pointer types (N2315 - 20.6.5.3.3)
template<typename _Up>
- typename std::enable_if<std::is_convertible<_Up*,
- pointer>::value>::type reset(_Up*);
-
+ unique_ptr(_Up*, typename
+ std::conditional<std::is_reference<deleter_type>::value,
+ deleter_type, const deleter_type&>::type,
+ typename std::enable_if<std::is_convertible<_Up*,
+ pointer>::value>::type* = 0) = delete;
+
+ template<typename _Up>
+ unique_ptr(_Up*, typename std::remove_reference<deleter_type>::type&&,
+ typename std::enable_if<std::is_convertible<_Up*,
+ pointer>::value>::type* = 0) = delete;
+
+ template<typename _Up>
+ explicit
+ unique_ptr(_Up*, typename std::enable_if<std::is_convertible<_Up*,
+ pointer>::value>::type* = 0) = delete;
+
private:
__tuple_type _M_t;
};
template<typename _Tp, typename _Tp_Deleter>
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<typename _Tp, typename _Tp_Deleter>
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<typename _Tp, typename _Tp_Deleter>
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<typename _Tp, typename _Tp_Deleter,
typename _Up, typename _Up_Deleter>
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<typename _Tp, typename _Tp_Deleter,
typename _Up, typename _Up_Deleter>
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 559ade3..3ccc870 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<int[]> p1(new int(420));
- std::unique_ptr<int[]> p2 = p1; // { dg-error "within this context" }
+ std::unique_ptr<int[]> p2 = p1;
}
void
test03()
{
std::unique_ptr<int[2]> p1(new int[3]);
- std::unique_ptr<int[2]> p2 = p1; // { dg-error "within this context" }
+ std::unique_ptr<int[2]> 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 0000000..37fcb6c
--- /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 <memory>
+
+struct A
+{
+};
+
+struct B : A
+{
+ virtual ~B() { }
+};
+
+void test01()
+{
+ std::unique_ptr<B[]> up;
+ up.reset(new A[3]);
+}
+
+// { dg-error "used here" "" { target *-*-* } 36 }
+// { dg-error "deleted function" "" { target *-*-* } 352 }