unique_ptr.h (unique_ptr<_Tp[]>::template<typename U> void reset(U)): Add as deleted function, per DR 821 [Ready].
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
This commit is contained in:
parent
58760a81d7
commit
0d5f7a16eb
|
@ -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>
|
2008-09-28 Chris Fairles <cfairles@gcc.gnu.org>
|
||||||
|
|
||||||
* include/std/mutex (try_lock): Implement generic try_lock.
|
* include/std/mutex (try_lock): Implement generic try_lock.
|
||||||
|
|
|
@ -84,15 +84,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
template <typename _Tp, typename _Tp_Deleter = default_delete<_Tp> >
|
template <typename _Tp, typename _Tp_Deleter = default_delete<_Tp> >
|
||||||
class unique_ptr
|
class unique_ptr
|
||||||
{
|
{
|
||||||
typedef _Tp* pointer;
|
typedef unique_ptr<_Tp, _Tp_Deleter> __this_type;
|
||||||
typedef unique_ptr<_Tp, _Tp_Deleter> __this_type;
|
typedef std::tuple<_Tp*, _Tp_Deleter> __tuple_type;
|
||||||
typedef std::tuple<pointer, _Tp_Deleter> __tuple_type;
|
typedef __tuple_type __this_type::* __unspecified_bool_type;
|
||||||
typedef __tuple_type __this_type::* __unspecified_bool_type;
|
typedef _Tp* __this_type::* __unspecified_pointer_type;
|
||||||
typedef pointer __this_type::* __unspecified_pointer_type;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef _Tp element_type;
|
typedef _Tp* pointer;
|
||||||
typedef _Tp_Deleter deleter_type;
|
typedef _Tp element_type;
|
||||||
|
typedef _Tp_Deleter deleter_type;
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
unique_ptr()
|
unique_ptr()
|
||||||
|
@ -195,7 +195,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
reset(pointer __p = 0)
|
reset(pointer __p = pointer())
|
||||||
{
|
{
|
||||||
if (__p != get())
|
if (__p != get())
|
||||||
{
|
{
|
||||||
|
@ -206,22 +206,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
|
|
||||||
void
|
void
|
||||||
swap(unique_ptr&& __u)
|
swap(unique_ptr&& __u)
|
||||||
{ using std::swap;
|
{
|
||||||
|
using std::swap;
|
||||||
swap(_M_t, __u._M_t);
|
swap(_M_t, __u._M_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
// disable copy from lvalue
|
// disable copy from lvalue
|
||||||
unique_ptr(const unique_ptr&);
|
unique_ptr(const unique_ptr&) = delete;
|
||||||
|
|
||||||
template<typename _Up, typename _Up_Deleter>
|
template<typename _Up, typename _Up_Deleter>
|
||||||
unique_ptr(const unique_ptr<_Up, _Up_Deleter>&);
|
unique_ptr(const unique_ptr<_Up, _Up_Deleter>&) = delete;
|
||||||
|
|
||||||
// disable assignment from lvalue
|
unique_ptr& operator=(const unique_ptr&) = delete;
|
||||||
unique_ptr& operator=(const unique_ptr&);
|
|
||||||
|
|
||||||
template<typename _Up, typename _Up_Deleter>
|
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:
|
private:
|
||||||
__tuple_type _M_t;
|
__tuple_type _M_t;
|
||||||
|
@ -234,14 +233,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
template<typename _Tp, typename _Tp_Deleter>
|
template<typename _Tp, typename _Tp_Deleter>
|
||||||
class unique_ptr<_Tp[], _Tp_Deleter>
|
class unique_ptr<_Tp[], _Tp_Deleter>
|
||||||
{
|
{
|
||||||
typedef _Tp* pointer;
|
typedef unique_ptr<_Tp[], _Tp_Deleter> __this_type;
|
||||||
typedef unique_ptr<_Tp[], _Tp_Deleter> __this_type;
|
typedef std::tuple<_Tp*, _Tp_Deleter> __tuple_type;
|
||||||
typedef std::tuple<pointer, _Tp_Deleter> __tuple_type;
|
typedef __tuple_type __this_type::* __unspecified_bool_type;
|
||||||
typedef __tuple_type __this_type::* __unspecified_bool_type;
|
typedef _Tp* __this_type::* __unspecified_pointer_type;
|
||||||
typedef pointer __this_type::* __unspecified_pointer_type;
|
|
||||||
public:
|
public:
|
||||||
typedef _Tp element_type;
|
typedef _Tp* pointer;
|
||||||
typedef _Tp_Deleter deleter_type;
|
typedef _Tp element_type;
|
||||||
|
typedef _Tp_Deleter deleter_type;
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
unique_ptr()
|
unique_ptr()
|
||||||
|
@ -338,7 +338,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
reset(pointer __p = 0)
|
reset(pointer __p = pointer())
|
||||||
{
|
{
|
||||||
if (__p != get())
|
if (__p != get())
|
||||||
{
|
{
|
||||||
|
@ -347,6 +347,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DR 821.
|
||||||
|
template<typename _Up>
|
||||||
|
void reset(_Up) = delete;
|
||||||
|
|
||||||
void
|
void
|
||||||
swap(unique_ptr&& __u)
|
swap(unique_ptr&& __u)
|
||||||
{
|
{
|
||||||
|
@ -354,32 +358,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
swap(_M_t, __u._M_t);
|
swap(_M_t, __u._M_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
// disable copy from lvalue
|
// disable copy from lvalue
|
||||||
unique_ptr(const unique_ptr&);
|
unique_ptr(const unique_ptr&) = delete;
|
||||||
unique_ptr& operator=(const unique_ptr&);
|
unique_ptr& operator=(const unique_ptr&) = delete;
|
||||||
|
|
||||||
// disable construction from convertible pointer types
|
// disable construction from convertible pointer types
|
||||||
// (N2315 - 20.6.5.3.1)
|
// (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>
|
template<typename _Up>
|
||||||
typename std::enable_if<std::is_convertible<_Up*,
|
unique_ptr(_Up*, typename
|
||||||
pointer>::value>::type reset(_Up*);
|
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:
|
private:
|
||||||
__tuple_type _M_t;
|
__tuple_type _M_t;
|
||||||
|
|
|
@ -40,13 +40,20 @@ void
|
||||||
test02()
|
test02()
|
||||||
{
|
{
|
||||||
std::unique_ptr<int[]> p1(new int(420));
|
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
|
void
|
||||||
test03()
|
test03()
|
||||||
{
|
{
|
||||||
std::unique_ptr<int[2]> p1(new int[3]);
|
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" }
|
||||||
|
|
|
@ -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 }
|
Loading…
Reference in New Issue