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
This commit is contained in:
parent
85f38b3ff3
commit
14b846de51
@ -106,9 +106,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
|||||||
typedef _Tp element_type;
|
typedef _Tp element_type;
|
||||||
typedef _Dp deleter_type;
|
typedef _Dp deleter_type;
|
||||||
|
|
||||||
static_assert(!std::is_pointer<deleter_type>::value,
|
|
||||||
"constructed with null function pointer deleter");
|
|
||||||
|
|
||||||
// Constructors.
|
// Constructors.
|
||||||
constexpr unique_ptr()
|
constexpr unique_ptr()
|
||||||
: _M_t()
|
: _M_t()
|
||||||
@ -132,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
|||||||
"rvalue deleter bound to reference"); }
|
"rvalue deleter bound to reference"); }
|
||||||
|
|
||||||
constexpr unique_ptr(nullptr_t)
|
constexpr unique_ptr(nullptr_t)
|
||||||
: _M_t(pointer(), deleter_type())
|
: _M_t()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// Move constructors.
|
// Move constructors.
|
||||||
@ -269,18 +266,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
|||||||
typedef _Tp element_type;
|
typedef _Tp element_type;
|
||||||
typedef _Dp deleter_type;
|
typedef _Dp deleter_type;
|
||||||
|
|
||||||
static_assert(!std::is_pointer<deleter_type>::value,
|
|
||||||
"constructed with null function pointer deleter");
|
|
||||||
|
|
||||||
// Constructors.
|
// Constructors.
|
||||||
constexpr unique_ptr()
|
constexpr unique_ptr()
|
||||||
: _M_t(pointer(), deleter_type())
|
: _M_t()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
unique_ptr(pointer __p)
|
unique_ptr(pointer __p)
|
||||||
: _M_t(__p, deleter_type())
|
: _M_t(__p, deleter_type())
|
||||||
{ }
|
{ static_assert(!std::is_pointer<deleter_type>::value,
|
||||||
|
"constructed with null function pointer deleter"); }
|
||||||
|
|
||||||
unique_ptr(pointer __p,
|
unique_ptr(pointer __p,
|
||||||
typename std::conditional<std::is_reference<deleter_type>::value,
|
typename std::conditional<std::is_reference<deleter_type>::value,
|
||||||
@ -295,7 +290,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
|||||||
|
|
||||||
/* TODO: use delegating constructor */
|
/* TODO: use delegating constructor */
|
||||||
constexpr unique_ptr(nullptr_t)
|
constexpr unique_ptr(nullptr_t)
|
||||||
: _M_t(pointer(), deleter_type())
|
: _M_t()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// Move constructors.
|
// Move constructors.
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user