OSDN Git Service

2010-11-08 Jonathan Wakely <jwakely.gcc@gmail.com>
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Nov 2010 23:42:09 +0000 (23:42 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Nov 2010 23:42:09 +0000 (23:42 +0000)
* include/bits/unique_ptr.h: Move misplaced static_assert and use
tuple's constexpr constructor in constexpr constructors.
* testsuite/20_util/unique_ptr/cons/ptr_deleter.cc: New.
* testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: New.

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

libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc [new file with mode: 0644]

index 4dc4ddd..ff1a925 100644 (file)
@@ -106,9 +106,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef _Tp                       element_type;
       typedef _Dp                       deleter_type;
 
-      static_assert(!std::is_pointer<deleter_type>::value,
-                   "constructed with null function pointer deleter");
-
       // Constructors.
       constexpr unique_ptr()
       : _M_t()
@@ -132,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                      "rvalue deleter bound to reference"); }
 
       constexpr unique_ptr(nullptr_t)
-      : _M_t(pointer(), deleter_type())
+      : _M_t()
       { }
 
       // Move constructors.
@@ -269,18 +266,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef _Tp                      element_type;
       typedef _Dp                       deleter_type;
 
-      static_assert(!std::is_pointer<deleter_type>::value,
-                   "constructed with null function pointer deleter");
-
       // Constructors.
       constexpr unique_ptr()
-      : _M_t(pointer(), deleter_type())
+      : _M_t()
       { }
 
       explicit
       unique_ptr(pointer __p)
       : _M_t(__p, deleter_type())
-      { }
+      { static_assert(!std::is_pointer<deleter_type>::value,
+                    "constructed with null function pointer deleter"); }
 
       unique_ptr(pointer __p,
          typename std::conditional<std::is_reference<deleter_type>::value,
@@ -295,7 +290,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 
       /* TODO: use delegating constructor */
       constexpr unique_ptr(nullptr_t)
-      : _M_t(pointer(), deleter_type())
+      : _M_t()
       { }
 
       // Move constructors.
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc
new file mode 100644 (file)
index 0000000..7e88eb9
--- /dev/null
@@ -0,0 +1,68 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do run }
+
+// 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.9.10 Template class unique_ptr [unique.ptr]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+static int count;
+
+void del(int* p) { ++count; delete p; }
+void vdel(int* p) { ++count; delete[] p; }
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  count = 0;
+  {
+    std::unique_ptr<int, void(*)(int*)> p(nullptr, del);
+  }
+  VERIFY( count == 0 );
+  {
+    std::unique_ptr<int, void(*)(int*)> p(new int, del);
+  }
+  VERIFY( count == 1 );
+}
+
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+  count = 0;
+  {
+    std::unique_ptr<int[], void(*)(int*)> p(nullptr, vdel);
+  }
+  VERIFY( count == 0 );
+  {
+    std::unique_ptr<int[], void(*)(int*)> p(new int[1], vdel);
+  }
+  VERIFY( count == 1 );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc
new file mode 100644 (file)
index 0000000..143578e
--- /dev/null
@@ -0,0 +1,57 @@
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+// 20.6.11 Template class unique_ptr [unique.ptr]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+using std::unique_ptr;
+
+// { dg-excess-errors "static assertion failed" }
+
+void
+test01()
+{
+  unique_ptr<int, void(*)(int*)> p1; // { dg-error "here" "" { xfail *-*-* } }
+
+  unique_ptr<int, void(*)(int*)> p2(nullptr); // { dg-error "here" "" { xfail *-*-* } }
+
+  unique_ptr<int, void(*)(int*)> p3(new int); // { dg-error "here" }
+}
+
+void
+test02()
+{
+  unique_ptr<int[], void(*)(int*)> p1; // { dg-error "here" "" { xfail *-*-* } }
+
+  unique_ptr<int[], void(*)(int*)> p2(nullptr); // { dg-error "here" "" { xfail *-*-* } }
+
+  unique_ptr<int[], void(*)(int*)> p3(new int[1]); // { dg-error "here" }
+}
+
+
+int
+main()
+{
+  test01();
+  test02();
+  return 0;
+}