From dcd400b56f01dd6429d78f1f187e4ab575424542 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 22 Sep 2006 15:54:52 +0000 Subject: [PATCH] type_traits (add_reference): Robustify vs reference to void. 2006-09-22 Paolo Carlini * 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 . * 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. From-SVN: r117147 --- libstdc++-v3/ChangeLog | 23 ++++++ libstdc++-v3/include/tr1/boost_shared_ptr.h | 71 +++++++------------ libstdc++-v3/include/tr1/memory | 1 + libstdc++-v3/include/tr1/type_traits | 23 +++--- libstdc++-v3/include/tr1/type_traits_fwd.h | 4 +- .../explicit_instantiation/1.cc | 31 ++++++++ .../shared_ptr/explicit_instantiation/1.cc | 31 ++++++++ .../weak_ptr/explicit_instantiation/1.cc | 31 ++++++++ .../reference_modifications/add_reference.cc | 5 +- libstdc++-v3/testsuite/util/testsuite_tr1.h | 4 +- 10 files changed, 166 insertions(+), 58 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc create mode 100644 libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc create mode 100644 libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b10764cbe47..425349e0fc3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,26 @@ +2006-09-22 Paolo Carlini + + * 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 . + * 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 * include/tr1/boost_shared_ptr.h: Trivial formatting fixes. diff --git a/libstdc++-v3/include/tr1/boost_shared_ptr.h b/libstdc++-v3/include/tr1/boost_shared_ptr.h index 03632075e46..4a6dca261a2 100644 --- a/libstdc++-v3/include/tr1/boost_shared_ptr.h +++ b/libstdc++-v3/include/tr1/boost_shared_ptr.h @@ -90,8 +90,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) 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. @@ -451,26 +451,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) struct __dynamic_cast_tag { }; struct __polymorphic_cast_tag { }; - template - struct __shared_ptr_reference - { typedef _Tp& __type; }; - - template<> - struct __shared_ptr_reference - { typedef void __type; }; - - template<> - struct __shared_ptr_reference - { typedef void __type; }; - - template<> - struct __shared_ptr_reference - { typedef void __type; }; - - template<> - struct __shared_ptr_reference - { typedef void __type; }; - // Support for enable_shared_from_this. @@ -497,8 +477,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template class __shared_ptr { - typedef typename __shared_ptr_reference<_Tp>::__type _Reference; - public: typedef _Tp element_type; @@ -589,7 +567,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) // 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 @@ -648,8 +626,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) 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); @@ -806,33 +784,33 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) // It is not possible to avoid spurious access violations since // in multithreaded programs r._M_ptr may be invalidated at any point. template - __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 - __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 __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 __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; } @@ -975,27 +953,30 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) class weak_ptr : public __weak_ptr<_Tp> { public: - weak_ptr() : __weak_ptr<_Tp>() { } + weak_ptr() + : __weak_ptr<_Tp>() { } template - weak_ptr(const __weak_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { } + weak_ptr(const __weak_ptr<_Tp1>& __r) + : __weak_ptr<_Tp>(__r) { } template - weak_ptr(const __shared_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { } + weak_ptr(const __shared_ptr<_Tp1>& __r) + : __weak_ptr<_Tp>(__r) { } template 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 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; } }; diff --git a/libstdc++-v3/include/tr1/memory b/libstdc++-v3/include/tr1/memory index 6befb91c6fa..94a04777a1e 100644 --- a/libstdc++-v3/include/tr1/memory +++ b/libstdc++-v3/include/tr1/memory @@ -44,6 +44,7 @@ #include #include #include +#include // tr1::add_reference #include diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 0f798319340..ccbfc606134 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -278,7 +278,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) 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::value> struct __is_empty_helper @@ -563,16 +563,23 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template struct remove_reference<_Tp&> { typedef _Tp type; }; - + + // NB: Careful with reference to void. + template::value + || is_reference<_Tp>::value)> + struct __add_reference_helper + { typedef _Tp& type; }; + + template + struct __add_reference_helper<_Tp, true> + { typedef _Tp type; }; + template struct add_reference - { typedef _Tp& type; }; + : public __add_reference_helper<_Tp> + { }; - template - struct add_reference<_Tp&> - { typedef _Tp& type; }; - - /// @brief array modififications [4.7.3]. + /// @brief array modifications [4.7.3]. template struct remove_extent { typedef _Tp type; }; diff --git a/libstdc++-v3/include/tr1/type_traits_fwd.h b/libstdc++-v3/include/tr1/type_traits_fwd.h index fded5492ca4..f2130b05ff2 100644 --- a/libstdc++-v3/include/tr1/type_traits_fwd.h +++ b/libstdc++-v3/include/tr1/type_traits_fwd.h @@ -1,6 +1,6 @@ // 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 @@ -202,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template struct add_reference; - /// @brief array modififications [4.7.3]. + /// @brief array modifications [4.7.3]. template struct remove_extent; diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc new file mode 100644 index 00000000000..b497ebb0a4a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc @@ -0,0 +1,31 @@ +// 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 +#include + +// { dg-do compile } + +using namespace __gnu_test; +using std::tr1::enable_shared_from_this; +template class enable_shared_from_this; +template class enable_shared_from_this; +template class enable_shared_from_this; +template class enable_shared_from_this; diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc new file mode 100644 index 00000000000..015e22ec79b --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc @@ -0,0 +1,31 @@ +// 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 +#include + +// { dg-do compile } + +using namespace __gnu_test; +using std::tr1::shared_ptr; +template class shared_ptr; +template class shared_ptr; +template class shared_ptr; +template class shared_ptr; diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc new file mode 100644 index 00000000000..6c22459dab6 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc @@ -0,0 +1,31 @@ +// 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 +#include + +// { dg-do compile } + +using namespace __gnu_test; +using std::tr1::weak_ptr; +template class weak_ptr; +template class weak_ptr; +template class weak_ptr; +template class weak_ptr; diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc index 68e4db8ebb7..29ad8c3d994 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc @@ -1,6 +1,6 @@ // 2004-12-08 Paolo Carlini // -// 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 @@ -37,6 +37,9 @@ void test01() VERIFY( (is_same::type, int*&>::value) ); VERIFY( (is_same::type, ClassType&>::value) ); VERIFY( (is_same::type, ClassType&>::value) ); + + VERIFY( (is_same::type, void>::value) ); + VERIFY( (is_same::type, const void>::value) ); } int main() diff --git a/libstdc++-v3/testsuite/util/testsuite_tr1.h b/libstdc++-v3/testsuite/util/testsuite_tr1.h index e47845658ae..b48f1a36b41 100644 --- a/libstdc++-v3/testsuite/util/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/util/testsuite_tr1.h @@ -95,7 +95,7 @@ namespace __gnu_test class DerivedType : public ClassType { }; - enum EnumType { }; + enum EnumType { e0 }; struct ConvType { operator int() const; }; @@ -181,7 +181,7 @@ namespace __gnu_test // For use in 8_c_compatibility. template - typename __gnu_cxx::__enable_if::value, + typename __gnu_cxx::__enable_if::__value, bool>::__type check_ret_type(T) { return true; }