]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
unique_ptr.h (unique_ptr<_Tp[]>::template<typename U> void reset(U)): Add as deleted...
authorPaolo Carlini <paolo.carlini@oracle.com>
Sun, 28 Sep 2008 15:47:45 +0000 (15:47 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 28 Sep 2008 15:47:45 +0000 (15:47 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign.cc
libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc [new file with mode: 0644]

index 74ec22612727a7f52b2462b239a5470147238790..3448d906d9521d78ed7a3ad2f527535a5021ff3c 100644 (file)
@@ -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.
index ead0acf9515b550fb983740cd7b93635e1e1ccf9..3123a79ccaecf4e6ea587105cfd132293dea7bc0 100644 (file)
@@ -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()); }
 
index 559ade35c1a56dd8c5145e011852d3e5e40fee59..3ccc8701a0cdfbddfa53240b04266f69c25baeb2 100644 (file)
@@ -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 (file)
index 0000000..37fcb6c
--- /dev/null
@@ -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 }