This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] libstdc++/24595
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- Date: Mon, 31 Oct 2005 18:13:30 +0100
- Subject: [Patch] libstdc++/24595
Hi,
fixing this issue it's easy, unless we *really* dislike get_deleter
being a real nonmember (as mandated by TR1, actually): the testcase
makes obvious that the "friend trick" cannot be used in this case.
Jonathan, all, please have a look.
Tested x86-linux.
Paolo.
/////////////////
2005-10-31 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/24595
* include/tr1/boost_shared_ptr.h (shared_ptr<>::get_deleter):
Move out of shared_ptr.
* testsuite/tr1/2_general_utilities/memory/shared_ptr/misc/24595.cc:
New.
Index: include/tr1/boost_shared_ptr.h
===================================================================
--- include/tr1/boost_shared_ptr.h (revision 106252)
+++ include/tr1/boost_shared_ptr.h (working copy)
@@ -674,27 +674,20 @@
_M_refcount.swap(__other._M_refcount);
}
+ void*
+ _M_get_deleter(const std::type_info& __ti) const
+ { return _M_refcount.get_deleter(__ti); }
+
private:
template <typename _Tp1>
bool
_M_less(const shared_ptr<_Tp1>& __rhs) const
{ return _M_refcount < __rhs._M_refcount; }
- void*
- _M_get_deleter(const std::type_info& __ti) const
- { return _M_refcount.get_deleter(__ti); }
-
template <typename _Tp1> friend class shared_ptr;
template <typename _Tp1> friend class weak_ptr;
// friends injected into enclosing namespace and found by ADL:
-
- // get_deleter (experimental)
- template <typename _Del>
- friend inline _Del*
- get_deleter(const shared_ptr& __p)
- { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); }
-
template <typename _Tp1>
friend inline bool
operator==(const shared_ptr& __a, const shared_ptr<_Tp1>& __b)
@@ -752,16 +745,22 @@
return shared_ptr<_Tp>(__r, __dynamic_cast_tag());
}
-// operator<<
+// 2.2.3.7 shared_ptr I/O
template <typename _Ch, typename _Tr, typename _Tp>
- std::basic_ostream<_Ch,_Tr>&
- operator<<(std::basic_ostream<_Ch,_Tr>& __os, const shared_ptr<_Tp>& __p)
+ std::basic_ostream<_Ch, _Tr>&
+ operator<<(std::basic_ostream<_Ch, _Tr>& __os, const shared_ptr<_Tp>& __p)
{
__os << __p.get();
return __os;
}
+// 2.2.3.10 shared_ptr get_deleter (experimental)
+template <typename _Del, typename _Tp>
+ inline _Del*
+ get_deleter(const shared_ptr<_Tp>& __p)
+ { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); }
+
template <typename _Tp>
class weak_ptr
{
Index: testsuite/tr1/2_general_utilities/memory/shared_ptr/misc/24595.cc
===================================================================
--- testsuite/tr1/2_general_utilities/memory/shared_ptr/misc/24595.cc (revision 0)
+++ testsuite/tr1/2_general_utilities/memory/shared_ptr/misc/24595.cc (revision 0)
@@ -0,0 +1,39 @@
+// Copyright (C) 2005 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_hooks.h>
+
+using std::tr1::get_deleter;
+
+// libstdc++/24595
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::tr1::shared_ptr<int> sp;
+ VERIFY( !get_deleter<void(*)(int*)>(sp) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}