OSDN Git Service

2010-04-24 Jonathan Wakely <jwakely.gcc@gmail.com>
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 24 Apr 2010 09:21:23 +0000 (09:21 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 24 Apr 2010 09:21:23 +0000 (09:21 +0000)
* include/bits/unique_ptr (unique_ptr::pointer): Use deleter's
pointer type if it exists.
* testsuite/20_util/unique_ptr/requirements/pointer_type.cc: New.
* testsuite/20_util/unique_ptr/assign/assign_neg.cc: Adjust.
* testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158682 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 96d166f..e722192 100644 (file)
@@ -1,3 +1,11 @@
+2010-04-24  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       * include/bits/unique_ptr (unique_ptr::pointer): Use deleter's
+       pointer type if it exists.
+       * testsuite/20_util/unique_ptr/requirements/pointer_type.cc: New.
+       * testsuite/20_util/unique_ptr/assign/assign_neg.cc: Adjust.
+       * testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: Adjust.
+
 2010-04-22  Johannes Singler  <singler@kit.edu>
 
         * include/parallel/partition.h (__parallel_partition):
index afa3043..7b07ca4 100644 (file)
@@ -83,10 +83,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef std::tuple<_Tp*, _Tp_Deleter>  __tuple_type;
       typedef _Tp* unique_ptr::*             __unspecified_pointer_type;
 
+      // use SFINAE to determine whether _Del::pointer exists
+      class _Pointer
+      {
+       template<typename _Up>
+         static typename _Up::pointer __test(typename _Up::pointer*);
+
+       template<typename _Up>
+         static _Tp* __test(...);
+
+       typedef typename remove_reference<_Tp_Deleter>::type _Del;
+
+      public:
+       typedef decltype( __test<_Del>(0) ) type;
+      };
+
     public:
-      typedef _Tp*               pointer;
-      typedef _Tp                element_type;      
-      typedef _Tp_Deleter        deleter_type;
+      typedef typename _Pointer::type  pointer;
+      typedef _Tp                       element_type;
+      typedef _Tp_Deleter               deleter_type;
 
       // Constructors.
       unique_ptr()
index 4bf8e4b..525364b 100644 (file)
@@ -49,13 +49,13 @@ test03()
   std::unique_ptr<int[2]> p2 = p1;
 }
 
-// { dg-error "deleted function" "" { target *-*-* } 342 }
+// { dg-error "deleted function" "" { target *-*-* } 357 }
 // { dg-error "used here" "" { target *-*-* } 42 }
 // { dg-error "no matching" "" { target *-*-* } 48 }
-// { dg-warning "candidates are" "" { target *-*-* } 115 }
-// { dg-warning "note" "" { target *-*-* } 108 }
-// { dg-warning "note" "" { target *-*-* } 103 }
-// { dg-warning "note" "" { target *-*-* } 98 }
-// { dg-warning "note" "" { target *-*-* } 92 }
-// { dg-error "deleted function" "" { target *-*-* } 207 }
+// { dg-warning "candidates are" "" { target *-*-* } 130 }
+// { dg-warning "note" "" { target *-*-* } 123 }
+// { dg-warning "note" "" { target *-*-* } 118 }
+// { dg-warning "note" "" { target *-*-* } 113 }
+// { dg-warning "note" "" { target *-*-* } 107 }
+// { dg-error "deleted function" "" { target *-*-* } 222 }
 // { dg-error "used here" "" { target *-*-* } 49 }
index 3308fcb..3b389b9 100644 (file)
@@ -36,4 +36,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 35 } 
-// { dg-error "deleted function" "" { target *-*-* } 332 }
+// { dg-error "deleted function" "" { target *-*-* } 347 }
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc
new file mode 100644 (file)
index 0000000..5074844
--- /dev/null
@@ -0,0 +1,50 @@
+// { dg-do compile }
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+// 20.6.11 Template class unique_ptr [unique.ptr.single]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A
+{
+  void operator()(void* p) const { }
+};
+
+struct B
+{
+  typedef char* pointer;
+  void operator()(pointer p) const { }
+};
+
+int main()
+{
+  typedef std::unique_ptr<int>            up;
+  typedef std::unique_ptr<int, A>  upA;
+  typedef std::unique_ptr<int, B>  upB;
+  typedef std::unique_ptr<int, A&> upAr;
+  typedef std::unique_ptr<int, B&> upBr;
+
+  static_assert( std::is_same< up::pointer, int*>::value, "" );
+  static_assert( std::is_same< upA::pointer, int*>::value, "" );
+  static_assert( std::is_same< upB::pointer, char*>::value, "" );
+  static_assert( std::is_same< upAr::pointer, int*>::value, "" );
+  static_assert( std::is_same< upBr::pointer, char*>::value, "" );
+}