mirror of git://gcc.gnu.org/git/gcc.git
Add std::get_deleter overload with correct signature
* include/bits/shared_ptr.h (get_deleter): Add overload matching standard signature. * include/bits/shared_ptr_base.h (__shared_ptr): Declare new get_deleter overload as a friend. * testsuite/20_util/shared_ptr/misc/get_deleter.cc: New. From-SVN: r249267
This commit is contained in:
parent
d7b11178c4
commit
78a8b676f1
|
|
@ -1,3 +1,11 @@
|
||||||
|
2017-06-16 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* include/bits/shared_ptr.h (get_deleter): Add overload matching
|
||||||
|
standard signature.
|
||||||
|
* include/bits/shared_ptr_base.h (__shared_ptr): Declare new
|
||||||
|
get_deleter overload as a friend.
|
||||||
|
* testsuite/20_util/shared_ptr/misc/get_deleter.cc: New.
|
||||||
|
|
||||||
2017-06-16 Jakub Jelinek <jakub@redhat.com>
|
2017-06-16 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
PR libstdc++/81092
|
PR libstdc++/81092
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
return __os;
|
return __os;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 20.7.2.2.10 shared_ptr get_deleter
|
|
||||||
template<typename _Del, typename _Tp, _Lock_policy _Lp>
|
template<typename _Del, typename _Tp, _Lock_policy _Lp>
|
||||||
inline _Del*
|
inline _Del*
|
||||||
get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept
|
get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept
|
||||||
|
|
@ -82,6 +81,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 20.7.2.2.10 shared_ptr get_deleter
|
||||||
|
template<typename _Del, typename _Tp>
|
||||||
|
inline _Del*
|
||||||
|
get_deleter(const shared_ptr<_Tp>& __p) noexcept
|
||||||
|
{
|
||||||
|
#if __cpp_rtti
|
||||||
|
return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del)));
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A smart pointer with reference-counted copy semantics.
|
* @brief A smart pointer with reference-counted copy semantics.
|
||||||
|
|
|
||||||
|
|
@ -1402,6 +1402,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
|
template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
|
||||||
friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept;
|
friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept;
|
||||||
|
|
||||||
|
template<typename _Del, typename _Tp1>
|
||||||
|
friend _Del* get_deleter(const shared_ptr<_Tp1>&) noexcept;
|
||||||
|
|
||||||
element_type* _M_ptr; // Contained pointer.
|
element_type* _M_ptr; // Contained pointer.
|
||||||
__shared_count<_Lp> _M_refcount; // Reference counter.
|
__shared_count<_Lp> _M_refcount; // Reference counter.
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright (C) 2017 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
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 3, 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 COPYING3. If not see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// { dg-do run { target c++11 } }
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
|
struct Del {
|
||||||
|
template<typename T> void operator()(T* p) const noexcept { delete p; }
|
||||||
|
};
|
||||||
|
|
||||||
|
Del* (*f1)(const std::shared_ptr<int>&) = std::get_deleter<Del, int>;
|
||||||
|
|
||||||
|
void
|
||||||
|
test01()
|
||||||
|
{
|
||||||
|
std::shared_ptr<int> p;
|
||||||
|
VERIFY( std::get_deleter<Del>(p) == nullptr );
|
||||||
|
p = std::shared_ptr<int>(new int, Del());
|
||||||
|
VERIFY( std::get_deleter<Del>(p) != nullptr );
|
||||||
|
p = std::shared_ptr<int>(new int);
|
||||||
|
VERIFY( std::get_deleter<Del>(p) == nullptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue