aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <redi@gcc.gnu.org>2010-11-08 23:42:09 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2010-11-08 23:42:09 +0000
commit14b846de5134c67084100ace478e353e93745f83 (patch)
tree1527e4153f3d6c0d7780f1c50dd87dc871cd5ae7 /libstdc++-v3
parent85f38b3ff3f14da35e0baef1e20be0cd4d6d21d9 (diff)
downloadgcc-14b846de5134c67084100ace478e353e93745f83.zip
gcc-14b846de5134c67084100ace478e353e93745f83.tar.gz
gcc-14b846de5134c67084100ace478e353e93745f83.tar.bz2
unique_ptr.h: Move misplaced static_assert and use tuple's constexpr constructor in constexpr...
2010-11-08 Jonathan Wakely <jwakely.gcc@gmail.com> * 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. From-SVN: r166460
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/unique_ptr.h15
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc68
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc57
3 files changed, 130 insertions, 10 deletions
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index 4dc4ddd..ff1a925 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -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
index 0000000..7e88eb9
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter.cc
@@ -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
index 0000000..143578e
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc
@@ -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;
+}