2006-09-22 Paolo Carlini <pcarlini@suse.de>
+ * include/tr1/type_traits (add_reference): Robustify vs
+ reference to void.
+ * testsuite/tr1/4_metaprogramming/reference_modifications/
+ add_reference.cc: Add test.
+
+ * include/tr1/memory: include <tr1/type_traits>.
+ * include/tr1/boost_shared_ptr.h (__shared_ptr<>::operator*):
+ Use add_reference instead.
+ * testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/
+ explicit_instantiation/1.cc: New.
+ * testsuite/tr1/2_general_utilities/memory/shared_ptr/
+ explicit_instantiation/1.cc: Likewise.
+ * testsuite/tr1/2_general_utilities/memory/weak_ptr/
+ explicit_instantiation/1.cc: Likewise.
+
+ * testsuite/util/testsuite_tr1.h: Tweak; avoid empty enum.
+
+ * include/tr1/type_traits_fwd.h: Spelling fix.
+
+ * include/tr1/boost_shared_ptr.h: Obvious stylistic fixes.
+
+2006-09-22 Paolo Carlini <pcarlini@suse.de>
+
* include/tr1/boost_shared_ptr.h: Trivial formatting fixes.
2006-09-21 Benjamin Kosnik <bkoz@redhat.com>
typedef _Tp* argument_type;
void
- operator()(_Tp* p) const
- { delete p; }
+ operator()(_Tp* __p) const
+ { delete __p; }
};
// Empty helper class except when the template argument is _S_mutex.
struct __dynamic_cast_tag { };
struct __polymorphic_cast_tag { };
- template<class _Tp>
- struct __shared_ptr_reference
- { typedef _Tp& __type; };
-
- template<>
- struct __shared_ptr_reference<void>
- { typedef void __type; };
-
- template<>
- struct __shared_ptr_reference<void const>
- { typedef void __type; };
-
- template<>
- struct __shared_ptr_reference<void volatile>
- { typedef void __type; };
-
- template<>
- struct __shared_ptr_reference<void const volatile>
- { typedef void __type; };
-
// Support for enable_shared_from_this.
template<typename _Tp, _Lock_policy _Lp>
class __shared_ptr
{
- typedef typename __shared_ptr_reference<_Tp>::__type _Reference;
-
public:
typedef _Tp element_type;
// delete r.release() well-formed
_Tp1 * __tmp = __r.get();
_M_refcount = shared_count<_Lp>(__r);
- __enable_shared_from_this_helper( _M_refcount, __tmp, __tmp );
+ __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp );
}
template<typename _Tp1>
reset(_Tp1 * __p, _Deleter __d)
{ __shared_ptr(__p, __d).swap(*this); }
- // Error to instantiate if _Tp is [cv-qual] void.
- _Reference
+ // Allow instantiation when _Tp is [cv-qual] void.
+ typename add_reference<_Tp>::type
operator*() const // never throws
{
_GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
// It is not possible to avoid spurious access violations since
// in multithreaded programs r._M_ptr may be invalidated at any point.
template<typename _Tp1>
- __weak_ptr(const __weak_ptr<_Tp1, _Lp>& r)
- : _M_refcount(r._M_refcount) // never throws
+ __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
+ : _M_refcount(__r._M_refcount) // never throws
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- _M_ptr = r.lock().get();
+ _M_ptr = __r.lock().get();
}
template<typename _Tp1>
- __weak_ptr(const __shared_ptr<_Tp1, _Lp>& r)
- : _M_ptr(r._M_ptr), _M_refcount(r._M_refcount) // never throws
+ __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
+ : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
{ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) }
template<typename _Tp1>
__weak_ptr&
- operator=(const __weak_ptr<_Tp1, _Lp>& r) // never throws
+ operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws
{
- _M_ptr = r.lock().get();
- _M_refcount = r._M_refcount;
+ _M_ptr = __r.lock().get();
+ _M_refcount = __r._M_refcount;
return *this;
}
template<typename _Tp1>
__weak_ptr&
- operator=(const __shared_ptr<_Tp1, _Lp>& r) // never throws
+ operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
{
- _M_ptr = r._M_ptr;
- _M_refcount = r._M_refcount;
+ _M_ptr = __r._M_ptr;
+ _M_refcount = __r._M_refcount;
return *this;
}
class weak_ptr : public __weak_ptr<_Tp>
{
public:
- weak_ptr() : __weak_ptr<_Tp>() { }
+ weak_ptr()
+ : __weak_ptr<_Tp>() { }
template<typename _Tp1>
- weak_ptr(const __weak_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { }
+ weak_ptr(const __weak_ptr<_Tp1>& __r)
+ : __weak_ptr<_Tp>(__r) { }
template<typename _Tp1>
- weak_ptr(const __shared_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { }
+ weak_ptr(const __shared_ptr<_Tp1>& __r)
+ : __weak_ptr<_Tp>(__r) { }
template<typename _Tp1>
weak_ptr&
- operator=(const weak_ptr<_Tp1>& r) // never throws
+ operator=(const weak_ptr<_Tp1>& __r) // never throws
{
- this->__weak_ptr<_Tp>::operator=(r);
+ this->__weak_ptr<_Tp>::operator=(__r);
return *this;
}
template<typename _Tp1>
weak_ptr&
- operator=(const shared_ptr<_Tp1>& r) // never throws
+ operator=(const shared_ptr<_Tp1>& __r) // never throws
{
- this->__weak_ptr<_Tp>::operator=(r);
+ this->__weak_ptr<_Tp>::operator=(__r);
return *this;
}
};
#include <ext/concurrence.h>
#include <bits/functexcept.h>
#include <debug/debug.h>
+#include <tr1/type_traits> // tr1::add_reference
#include <tr1/boost_shared_ptr.h>
remove_all_extents<_Tp>::type>::value)>
{ };
- // N.B. Without compiler support we cannot tell union from class types,
+ // NB: Without compiler support we cannot tell union from class types,
// and is_empty and is_polymorphic don't work at all with the former.
template<typename _Tp, bool = !__is_union_or_class<_Tp>::value>
struct __is_empty_helper
template<typename _Tp>
struct remove_reference<_Tp&>
{ typedef _Tp type; };
-
- template<typename _Tp>
- struct add_reference
+
+ // NB: Careful with reference to void.
+ template<typename _Tp, bool = (is_void<_Tp>::value
+ || is_reference<_Tp>::value)>
+ struct __add_reference_helper
{ typedef _Tp& type; };
template<typename _Tp>
- struct add_reference<_Tp&>
- { typedef _Tp& type; };
+ struct __add_reference_helper<_Tp, true>
+ { typedef _Tp type; };
+
+ template<typename _Tp>
+ struct add_reference
+ : public __add_reference_helper<_Tp>
+ { };
- /// @brief array modififications [4.7.3].
+ /// @brief array modifications [4.7.3].
template<typename _Tp>
struct remove_extent
{ typedef _Tp type; };
// TR1 type_traits -*- C++ -*-
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
//
// 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
template<typename _Tp>
struct add_reference;
- /// @brief array modififications [4.7.3].
+ /// @brief array modifications [4.7.3].
template<typename _Tp>
struct remove_extent;
--- /dev/null
+// Copyright (C) 2006 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.
+
+// TR1 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::enable_shared_from_this;
+template class enable_shared_from_this<int>;
+template class enable_shared_from_this<void>;
+template class enable_shared_from_this<ClassType>;
+template class enable_shared_from_this<IncompleteClass>;
--- /dev/null
+// Copyright (C) 2006 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.
+
+// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::shared_ptr;
+template class shared_ptr<int>;
+template class shared_ptr<void>;
+template class shared_ptr<ClassType>;
+template class shared_ptr<IncompleteClass>;
--- /dev/null
+// Copyright (C) 2006 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.
+
+// TR1 2.2.4 Template class weak_ptr [tr.util.smartptr.weak]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::weak_ptr;
+template class weak_ptr<int>;
+template class weak_ptr<void>;
+template class weak_ptr<ClassType>;
+template class weak_ptr<IncompleteClass>;
// 2004-12-08 Paolo Carlini <pcarlini@suse.de>
//
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
//
// 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
VERIFY( (is_same<add_reference<int*>::type, int*&>::value) );
VERIFY( (is_same<add_reference<ClassType&>::type, ClassType&>::value) );
VERIFY( (is_same<add_reference<ClassType>::type, ClassType&>::value) );
+
+ VERIFY( (is_same<add_reference<void>::type, void>::value) );
+ VERIFY( (is_same<add_reference<const void>::type, const void>::value) );
}
int main()
class DerivedType : public ClassType { };
- enum EnumType { };
+ enum EnumType { e0 };
struct ConvType
{ operator int() const; };
// For use in 8_c_compatibility.
template<typename R, typename T>
- typename __gnu_cxx::__enable_if<std::tr1::is_same<R, T>::value,
+ typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
bool>::__type
check_ret_type(T)
{ return true; }