+2008-11-01 Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ * include/bits/shared_ptr.h: Update comparisons to match WP.
+ (_Sp_counted_ptr): Make copy and assignment members deleted.
+ (_Sp_counted_deleter): Remove private copy and assignment members.
+ (__shared_count::_M_less,__weak_count::_M_less,operator<): Replace
+ friend operator< with overloaded _M_less member functions to allow
+ comparison with either shared_count or weak_count.
+ (__shared_ptr::_M_less,__weak_ptr::_M_less): Replace with...
+ (__shared_ptr::owner_before,__weak_ptr::owner_before): New overloads
+ for ownership-based ordering.
+ (operator<(__shared_ptr,__shared_ptr)): Compare stored pointers,
+ make non-friend.
+ (operator==(__shared_ptr,__shared_ptr)): Make non-friend.
+ (operator!=(__shared_ptr,__shared_ptr)): Likewise.
+ (less<__shared_ptr<>>,less<shared_ptr<>>,_Sp_less): Explicitly call
+ pointer specialization.
+ (__weak_ptr::operator<,weak_ptr::operator<=,weak_ptr::operator>,
+ weak_ptr::operator>=): Remove operator< and delete all comparisons.
+ (_Sp_owner_less,owner_less): Predicate for ownership-based ordering.
+ (operator<(shared_ptr,shared_ptr): Overload for derived shared_ptr.
+ (operator==(shared_ptr,shared_ptr): Likewise.
+ (operator!=(shared_ptr,shared_ptr): Likewise.
+ (swap(shared_ptr,shared_ptr)): Fix parameter types.
+ (swap(weak_ptr,weak_ptr)): Add missing overload.
+ * testsuite/20_util/owner_less/cmp.cc: New.
+ * testsuite/20_util/shared_ptr/comparison/cmp.cc: Test other ops.
+ * testsuite/20_util/shared_ptr/comparison/less.cc: New.
+ * testsuite/20_util/shared_ptr/observers/owner_before.cc: New.
+ * testsuite/20_util/weak_ptr/observers/owner_before.cc: New.
+ * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: New.
+
2008-10-31 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/37958
_M_get_deleter(const std::type_info& __ti)
{ return 0; }
- private:
- _Sp_counted_ptr(const _Sp_counted_ptr&);
- _Sp_counted_ptr& operator=(const _Sp_counted_ptr&);
+ _Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
+ _Sp_counted_ptr& operator=(const _Sp_counted_ptr&) = delete;
protected:
_Ptr _M_ptr; // copy constructor must not throw
_M_get_deleter(const std::type_info& __ti)
{ return __ti == typeid(_Deleter) ? &_M_del._M_del : 0; }
- private:
- _Sp_counted_deleter(const _Sp_counted_deleter&);
- _Sp_counted_deleter& operator=(const _Sp_counted_deleter&);
-
protected:
_My_Deleter _M_del; // copy constructor must not throw
};
_M_unique() const // nothrow
{ return this->_M_get_use_count() == 1; }
- friend inline bool
- operator==(const __shared_count& __a, const __shared_count& __b)
- { return __a._M_pi == __b._M_pi; }
-
- friend inline bool
- operator<(const __shared_count& __a, const __shared_count& __b)
- { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); }
-
void*
_M_get_deleter(const std::type_info& __ti) const
{ return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; }
+ bool
+ _M_less(const __shared_count& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ bool
+ _M_less(const __weak_count<_Lp>& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ // friend function injected into enclosing namespace and found by ADL
+ friend inline bool
+ operator==(const __shared_count& __a, const __shared_count& __b)
+ { return __a._M_pi == __b._M_pi; }
+
private:
friend class __weak_count<_Lp>;
_M_get_use_count() const // nothrow
{ return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
+ bool
+ _M_less(const __weak_count& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ bool
+ _M_less(const __shared_count<_Lp>& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ // friend function injected into enclosing namespace and found by ADL
friend inline bool
- operator==(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b)
+ operator==(const __weak_count& __a, const __weak_count& __b)
{ return __a._M_pi == __b._M_pi; }
-
- friend inline bool
- operator<(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b)
- { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); }
private:
friend class __shared_count<_Lp>;
_M_refcount._M_swap(__other._M_refcount);
}
+ template<typename _Tp1>
+ bool
+ owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ template<typename _Tp1>
+ bool
+ owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
protected:
// This constructor is non-standard, it is used by allocate_shared.
template<typename _Alloc, typename... _Args>
_M_get_deleter(const std::type_info& __ti) const
{ return _M_refcount._M_get_deleter(__ti); }
- template<typename _Tp1, _Lock_policy _Lp1>
- bool
- _M_less(const __shared_ptr<_Tp1, _Lp1>& __rhs) const
- { return _M_refcount < __rhs._M_refcount; }
-
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&);
- // Friends injected into enclosing namespace and found by ADL:
- template<typename _Tp1>
- friend inline bool
- operator==(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b)
- { return __a.get() == __b.get(); }
-
- template<typename _Tp1>
- friend inline bool
- operator!=(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b)
- { return __a.get() != __b.get(); }
-
- template<typename _Tp1>
- friend inline bool
- operator<(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b)
- { return __a._M_less(__b); }
-
_Tp* _M_ptr; // Contained pointer.
__shared_count<_Lp> _M_refcount; // Reference counter.
};
+ // 20.8.13.2.7 shared_ptr comparisons
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator==(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() == __b.get(); }
+
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator!=(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() != __b.get(); }
+
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator<(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() < __b.get(); }
+
+ template<typename _Sp>
+ struct _Sp_less : public binary_function<_Sp, _Sp, bool>
+ {
+ bool
+ operator()(const _Sp& __lhs, const _Sp& __rhs) const
+ {
+ return std::less<typename _Sp::element_type*>()(__lhs.get(),
+ __rhs.get());
+ }
+ };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct less<__shared_ptr<_Tp, _Lp>>
+ : public _Sp_less<__shared_ptr<_Tp, _Lp>>
+ { };
+
+ // XXX LessThanComparable<_Tp> concept should provide >, >= and <=
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator>(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() > __b.get(); }
+
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator>=(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() >= __b.get(); }
+
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator<=(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() <= __b.get(); }
+
// 2.2.3.8 shared_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
bool
expired() const // never throws
{ return _M_refcount._M_get_use_count() == 0; }
-
+
+ template<typename _Tp1>
+ bool
+ owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ template<typename _Tp1>
+ bool
+ owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
void
reset() // never throws
{ __weak_ptr().swap(*this); }
_M_refcount._M_swap(__s._M_refcount);
}
+ // comparisons
+ template<typename _Tp1>
+ bool operator<(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+ template<typename _Tp1>
+ bool operator<=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+ template<typename _Tp1>
+ bool operator>(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+ template<typename _Tp1>
+ bool operator>=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+
private:
// Used by __enable_shared_from_this.
void
_M_refcount = __refcount;
}
- template<typename _Tp1>
- bool
- _M_less(const __weak_ptr<_Tp1, _Lp>& __rhs) const
- { return _M_refcount < __rhs._M_refcount; }
-
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
friend class __enable_shared_from_this<_Tp, _Lp>;
friend class enable_shared_from_this<_Tp>;
- // Friend injected into namespace and found by ADL.
- template<typename _Tp1>
- friend inline bool
- operator<(const __weak_ptr& __lhs, const __weak_ptr<_Tp1, _Lp>& __rhs)
- { return __lhs._M_less(__rhs); }
-
_Tp* _M_ptr; // Contained pointer.
__weak_count<_Lp> _M_refcount; // Reference counter.
};
- // 2.2.4.7 weak_ptr specialized algorithms.
+ // 20.8.13.3.7 weak_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b)
{ __a.swap(__b); }
+ /// owner_less
+ template<typename _Tp> struct owner_less;
+
+ template<typename _Tp, typename _Tp1>
+ struct _Sp_owner_less : public binary_function<_Tp, _Tp, bool>
+ {
+ bool
+ operator()(const _Tp& __lhs, const _Tp& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+ bool
+ operator()(const _Tp& __lhs, const _Tp1& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+ bool
+ operator()(const _Tp1& __lhs, const _Tp& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+ };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct owner_less<__shared_ptr<_Tp, _Lp>>
+ : public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
+ { };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct owner_less<__weak_ptr<_Tp, _Lp>>
+ : public _Sp_owner_less<__weak_ptr<_Tp, _Lp>, __shared_ptr<_Tp, _Lp>>
+ {
+ };
+
template<typename _Tp, _Lock_policy _Lp>
class __enable_shared_from_this
allocate_shared(_Alloc __a, _Args&&... __args);
};
- // 20.7.12.2.9 shared_ptr specialized algorithms.
+ // 20.8.13.2.7 shared_ptr comparisons
+ template<typename _Tp1, typename _Tp2>
+ inline bool
+ operator==(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
+ { return __a.get() == __b.get(); }
+
+ template<typename _Tp1, typename _Tp2>
+ inline bool
+ operator!=(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
+ { return __a.get() != __b.get(); }
+
+ template<typename _Tp1, typename _Tp2>
+ inline bool
+ operator<(const shared_ptr<_Tp1>& __a, const shared_ptr<_Tp2>& __b)
+ { return __a.get() < __b.get(); }
+
+ template<typename _Tp>
+ struct less<shared_ptr<_Tp>>
+ : public _Sp_less<shared_ptr<_Tp>>
+ { };
+
+ // 20.8.13.2.9 shared_ptr specialized algorithms.
template<typename _Tp>
inline void
- swap(__shared_ptr<_Tp>& __a, __shared_ptr<_Tp>& __b)
+ swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b)
{ __a.swap(__b); }
template<typename _Tp>
inline void
- swap(__shared_ptr<_Tp>&& __a, __shared_ptr<_Tp>& __b)
+ swap(shared_ptr<_Tp>&& __a, shared_ptr<_Tp>& __b)
{ __a.swap(__b); }
template<typename _Tp>
inline void
- swap(__shared_ptr<_Tp>& __a, __shared_ptr<_Tp>&& __b)
+ swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>&& __b)
{ __a.swap(__b); }
+ // 20.8.13.2.10 shared_ptr casts.
template<typename _Tp, typename _Tp1>
inline shared_ptr<_Tp>
static_pointer_cast(const shared_ptr<_Tp1>& __r)
: shared_ptr<_Tp>(*this);
#endif
}
+
+ // comparisons
+ template<typename _Tp1>
+ bool operator<(const weak_ptr<_Tp1>&) const = delete;
+ template<typename _Tp1>
+ bool operator<=(const weak_ptr<_Tp1>&) const = delete;
+ template<typename _Tp1>
+ bool operator>(const weak_ptr<_Tp1>&) const = delete;
+ template<typename _Tp1>
+ bool operator>=(const weak_ptr<_Tp1>&) const = delete;
};
+ // 20.8.13.3.7 weak_ptr specialized algorithms.
+ template<typename _Tp>
+ inline void
+ swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b)
+ { __a.swap(__b); }
+
+ /// owner_less
+ template<typename _Tp>
+ struct owner_less<shared_ptr<_Tp>>
+ : public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
+ { };
+
+ template<typename _Tp>
+ struct owner_less<weak_ptr<_Tp>>
+ : public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
+ { };
+
/// enable_shared_from_this
template<typename _Tp>
class enable_shared_from_this
--- /dev/null
+// { 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.
+
+// 20.8.13.4 Template class owner_less [util.smartptr.ownerless]
+
+#include <memory>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+struct A { };
+
+struct B { A a[2]; };
+
+// 20.8.13.4 Template class owner_less [util.smartptr.ownerless]
+
+int
+test01()
+{
+ // test empty shared_ptrs compare equivalent
+ std::owner_less<std::shared_ptr<A>> less;
+ std::owner_less<std::weak_ptr<A>> wless;
+ std::shared_ptr<A> p1;
+ std::shared_ptr<A> p2;
+ VERIFY( !less(p1, p2) && !less(p2, p1) );
+ std::weak_ptr<A> p3;
+ VERIFY( !less(p1, p3) && !less(p3, p1) );
+ VERIFY( !wless(p1, p3) && !wless(p3, p1) );
+ return 0;
+}
+
+
+// Construction from pointer
+int
+test02()
+{
+ std::owner_less<std::shared_ptr<A>> less;
+ std::owner_less<std::weak_ptr<A>> wless;
+
+ std::shared_ptr<A> empty;
+
+ std::shared_ptr<A> a1(new A);
+ VERIFY( less(empty, a1) || less(a1, empty) );
+
+ std::shared_ptr<A> a2(new A);
+ VERIFY( less(a1, a2) || less(a2, a1) );
+
+ std::weak_ptr<A> w1(a1);
+ VERIFY( !less(a1, w1) && !less(w1, a1) );
+
+ std::weak_ptr<A> w2(a2);
+ VERIFY( wless(w1, w2) || wless(w2, w1) );
+
+ a1.reset();
+ VERIFY( !less(empty, a1) && !less(a1, empty) );
+ VERIFY( less(a1, w1) || less(w1, a1) );
+
+ a2.reset();
+ VERIFY( !less(a2, a1) && !less(a1, a2) );
+
+ return 0;
+}
+
+// aliasing
+int
+test03()
+{
+ std::owner_less<std::shared_ptr<A>> less;
+ std::owner_less<std::weak_ptr<A>> wless;
+
+ std::shared_ptr<B> b(new B);
+ std::shared_ptr<A> a0(b, &b->a[0]);
+ std::shared_ptr<A> a1(b, &b->a[1]);
+ // values are different but owners are equivalent:
+ VERIFY( a0 < a1 && !less(a0, a1) && !less(a1, a0) );
+
+ std::weak_ptr<A> w0(a0);
+ std::weak_ptr<A> w1(a1);
+ VERIFY( !wless(w0, w1) && !wless(w1, w0) );
+ VERIFY( !less(a0, w1) && !less(w1, a0) );
+ VERIFY( !wless(w0, a1) && !wless(a1, w0) );
+
+ return 0;
+}
+
+// strict weak ordering
+int
+test04()
+{
+ std::owner_less<std::shared_ptr<A>> less;
+
+ std::shared_ptr<A> a[3];
+ a[0].reset(new A);
+ a[1].reset(new A);
+ a[2].reset(new A);
+ std::sort(a, a+3, less);
+ VERIFY( !less(a[0], a[0]) );
+ VERIFY( less(a[0], a[1]) && !less(a[1], a[0]) );
+ VERIFY( less(a[0], a[1]) && less(a[1], a[2]) && less(a[0], a[2]) );
+
+ return 0;
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+ return 0;
+}
return 0;
}
+int
+test03()
+{
+ std::shared_ptr<A> p1;
+
+ // check other operators are defined
+ VERIFY( p1 <= p1 );
+ VERIFY( p1 >= p1 );
+ VERIFY( !(p1 > p1) );
+
+ return 0;
+}
+
int
main()
{
test01();
test02();
+ test03();
return 0;
}
--- /dev/null
+// { 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.
+
+// 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A { };
+
+namespace std
+{
+ template<>
+ struct less<A*> : binary_function<A*,A*,bool>
+ {
+ static int count;
+ bool operator()(A* l, A* r) { ++count; return l < r; }
+ };
+ int less<A*>::count = 0;
+}
+
+// 20.8.13.2.7 shared_ptr comparison [util.smartptr.shared.cmp]
+
+
+int
+test01()
+{
+ std::less<std::shared_ptr<A>> less;
+ // test empty shared_ptrs compare equivalent
+ std::shared_ptr<A> p1;
+ std::shared_ptr<A> p2;
+ VERIFY( !less(p1, p2) && !less(p2, p1) );
+ VERIFY( std::less<A*>::count == 2 );
+ return 0;
+}
+
+
+// Construction from pointer
+int
+test02()
+{
+ std::less<std::shared_ptr<A>> less;
+
+ std::shared_ptr<A> empty;
+ std::shared_ptr<A> p1(new A);
+ std::shared_ptr<A> p2(new A);
+
+ VERIFY( less(p1, p2) || less(p2, p1) );
+ VERIFY( !(less(p1, p2) && less(p2, p1)) );
+
+ p1.reset();
+ VERIFY( !less(p1, empty) && !less(empty, p1) );
+
+ p2.reset();
+ VERIFY( !less(p1, p2) && !less(p2, p1) );
+
+ return 0;
+}
+
+// Aliasing
+int
+test03()
+{
+ std::less<std::shared_ptr<A>> less;
+
+ A a;
+ std::shared_ptr<A> p1(new A);
+ std::shared_ptr<A> p2(p1, &a);
+ VERIFY( less(p1, p2) || less(p2, p1) );
+
+ return 0;
+}
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
// { dg-options "-std=gnu++0x" }
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation
+// Copyright (C) 2005, 2006, 2007, 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
// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
// conversion to bool
-int
+void
test01()
{
bool test __attribute__((unused)) = true;
VERIFY( p1 == false );
const std::shared_ptr<A> p2(p1);
VERIFY( p2 == false );
-
- return 0;
}
-int
+void
test02()
{
bool test __attribute__((unused)) = true;
p1.reset();
VERIFY( !p1 );
VERIFY( p2 );
-
- return 0;
}
-int
+void
test03()
{
bool test __attribute__((unused)) = true;
p2.reset(new A);
VERIFY( p1 );
VERIFY( p2 );
-
- return 0;
}
// { dg-options "-std=gnu++0x" }
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation
+// Copyright (C) 2005, 2006, 2007, 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
// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
// get
-int
+void
test01()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::shared_ptr<A> p(a);
VERIFY( p.get() == a );
-
- return 0;
}
// operator*
-int
+void
test02()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::shared_ptr<A> p(a);
VERIFY( &*p == a );
-
- return 0;
}
-
// operator->
-int
+void
test03()
{
bool test __attribute__((unused)) = true;
A * const a = new A;
const std::shared_ptr<A> p(a);
VERIFY( &p->i == &a->i );
-
- return 0;
}
-
int
main()
{
--- /dev/null
+// { 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.
+
+// 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A
+{
+ int i;
+ virtual ~A() { }
+};
+
+struct B : A
+{
+};
+
+// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ // test empty shared_ptrs compare equivalent
+ std::shared_ptr<A> p1;
+ std::shared_ptr<B> p2;
+ VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
+}
+
+
+// Construction from pointer
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::shared_ptr<A> a0;
+
+ std::shared_ptr<A> a1(new A);
+ VERIFY( a1.owner_before(a0) || a0.owner_before(a1) );
+ VERIFY( !(a1.owner_before(a0) && a0.owner_before(a1)) );
+
+ std::shared_ptr<B> b1(new B);
+ VERIFY( a1.owner_before(b1) || b1.owner_before(a1) );
+ VERIFY( !(a1.owner_before(b1) && b1.owner_before(a1)) );
+
+ std::shared_ptr<A> a2(a1);
+ VERIFY( !a1.owner_before(a2) && !a2.owner_before(a1) );
+ a2 = b1;
+ VERIFY( !b1.owner_before(a2) && !a2.owner_before(b1) );
+
+ std::weak_ptr<A> w1(a1);
+ VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
+ std::weak_ptr<A> w2(a2);
+ VERIFY( !b1.owner_before(w2) && !w2.owner_before(b1) );
+}
+
+// Aliasing
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::shared_ptr<A> p1(new A());
+ std::shared_ptr<int> p2(p1, &p1->i);
+ VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
// { dg-options "-std=gnu++0x" }
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation
+// Copyright (C) 2005, 2006, 2007, 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
// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
// unique
-int
+void
test01()
{
bool test __attribute__((unused)) = true;
VERIFY( !p1.unique() );
const std::shared_ptr<A> p2(p1);
VERIFY( !p1.unique() );
-
- return 0;
}
-int
+void
test02()
{
bool test __attribute__((unused)) = true;
p1.reset();
VERIFY( !p1.unique() );
VERIFY( p2.unique() );
-
- return 0;
}
-int
+void
test03()
{
bool test __attribute__((unused)) = true;
p2.reset(new A);
VERIFY( p1.unique() );
VERIFY( p2.unique() );
-
- return 0;
}
// { dg-options "-std=gnu++0x" }
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation
+// Copyright (C) 2005, 2006, 2007, 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
// 20.6.6.2.5 shared_ptr observers [util.smartptr.shared.obs]
// use_count
-int
+void
test01()
{
bool test __attribute__((unused)) = true;
VERIFY( p1.use_count() == 0 );
const std::shared_ptr<A> p2(p1);
VERIFY( p1.use_count() == 0 );
-
- return 0;
}
-int
+void
test02()
{
bool test __attribute__((unused)) = true;
p1.reset();
VERIFY( p1.use_count() == 0 );
VERIFY( p2.use_count() == 1 );
-
- return 0;
}
-int
+void
test03()
{
bool test __attribute__((unused)) = true;
p2.reset(new B);
VERIFY( p1.use_count() == 1 );
VERIFY( p2.use_count() == 1 );
-
- return 0;
}
--- /dev/null
+// { dg-options "-std=gnu++0x " }
+// { dg-do compile }
+
+// 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.
+
+// 20.6.6.3 Template class weak_ptr [util.smartptr.weak]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A { };
+
+// 20.8.13.3.6 weak_ptr comparison [util.smartptr.weak.cmp] (removed)
+
+int
+test01()
+{
+ std::weak_ptr<A> p1;
+ // { dg-excess-errors "deleted function" }
+ p1 < p1; // { dg-error "used here" }
+ return 0;
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { 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.
+
+// 20.8.13.3 Template class weak_ptr [util.smartptr.weak]
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A { };
+struct B { };
+
+// 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
+
+int
+test01()
+{
+ // test empty weak_ptrs compare equivalent
+ std::weak_ptr<A> p1;
+ std::weak_ptr<B> p2;
+ VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
+
+ std::shared_ptr<B> p3;
+ VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) );
+
+ return 0;
+}
+
+
+int
+test02()
+{
+ std::shared_ptr<A> a0;
+ std::weak_ptr<A> w0(a0);
+
+ std::shared_ptr<A> a1(new A);
+ std::weak_ptr<A> w1(a1);
+ VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
+
+ VERIFY( w1.owner_before(w0) || w0.owner_before(w1) );
+ VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) );
+
+ VERIFY( w1.owner_before(a0) || a0.owner_before(w1) );
+ VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) );
+
+ std::shared_ptr<B> b1(new B);
+ VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
+
+ return 0;
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ return 0;
+}