mirror of git://gcc.gnu.org/git/gcc.git
PR libstdc++/88738 treat shared_ptr and unique_ptr more like plain old pointers
PR libstdc++/88738
Warn about unused comparisons of shared_ptr/unique_ptr
* include/bits/c++config [_GLIBCXX_NODISCARD]: Define.
* include/bits/shared_ptr.h: Use it for operator ==, !=,
<, <=, >, >= for shared_ptr.
* include/bits/unique_ptr.h: Likewise for unique_ptr.
From-SVN: r267964
This commit is contained in:
parent
df1de06415
commit
ec0d53719f
|
|
@ -1,3 +1,12 @@
|
||||||
|
2019-02-14 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
PR libstdc++/88738
|
||||||
|
Warn about unused comparisons of shared_ptr/unique_ptr
|
||||||
|
* include/bits/c++config [_GLIBCXX_NODISCARD]: Define.
|
||||||
|
* include/bits/shared_ptr.h: Use it for operator ==, !=,
|
||||||
|
<, <=, >, >= for shared_ptr.
|
||||||
|
* include/bits/unique_ptr.h: Likewise for unique_ptr.
|
||||||
|
|
||||||
2019-01-15 Jonathan Wakely <jwakely@redhat.com>
|
2019-01-15 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
* include/bits/shared_ptr_base.h (__cpp_lib_shared_ptr_arrays): Define
|
* include/bits/shared_ptr_base.h (__cpp_lib_shared_ptr_arrays): Define
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,14 @@
|
||||||
# define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
|
# define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Macro to warn about unused results.
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
# define _GLIBCXX_NODISCARD [[__nodiscard__]]
|
||||||
|
#else
|
||||||
|
# define _GLIBCXX_NODISCARD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -380,37 +380,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
|
|
||||||
// 20.7.2.2.7 shared_ptr comparisons
|
// 20.7.2.2.7 shared_ptr comparisons
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator==(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{ return __a.get() == __b.get(); }
|
{ return __a.get() == __b.get(); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{ return !__a; }
|
{ return !__a; }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{ return !__a; }
|
{ return !__a; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator!=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{ return __a.get() != __b.get(); }
|
{ return __a.get() != __b.get(); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator!=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{ return (bool)__a; }
|
{ return (bool)__a; }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator!=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{ return (bool)__a; }
|
{ return (bool)__a; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator<(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{
|
{
|
||||||
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
||||||
|
|
@ -420,7 +420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator<(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{
|
{
|
||||||
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
||||||
|
|
@ -428,7 +428,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator<(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{
|
{
|
||||||
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
using _Tp_elt = typename shared_ptr<_Tp>::element_type;
|
||||||
|
|
@ -436,47 +436,47 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator<=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{ return !(__b < __a); }
|
{ return !(__b < __a); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator<=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{ return !(nullptr < __a); }
|
{ return !(nullptr < __a); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator<=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{ return !(__a < nullptr); }
|
{ return !(__a < nullptr); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator>(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{ return (__b < __a); }
|
{ return (__b < __a); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator>(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{ return nullptr < __a; }
|
{ return nullptr < __a; }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator>(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{ return __a < nullptr; }
|
{ return __a < nullptr; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Up>
|
template<typename _Tp, typename _Up>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
operator>=(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
|
||||||
{ return !(__a < __b); }
|
{ return !(__a < __b); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
operator>=(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
|
||||||
{ return !(__a < nullptr); }
|
{ return !(__a < nullptr); }
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
|
||||||
{ return !(nullptr < __a); }
|
{ return !(nullptr < __a); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -707,41 +707,41 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(const unique_ptr<_Tp, _Dp>& __x,
|
operator==(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{ return __x.get() == __y.get(); }
|
{ return __x.get() == __y.get(); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
|
operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
|
||||||
{ return !__x; }
|
{ return !__x; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
|
operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
|
||||||
{ return !__x; }
|
{ return !__x; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(const unique_ptr<_Tp, _Dp>& __x,
|
operator!=(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{ return __x.get() != __y.get(); }
|
{ return __x.get() != __y.get(); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
|
operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
|
||||||
{ return (bool)__x; }
|
{ return (bool)__x; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
|
operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
|
||||||
{ return (bool)__x; }
|
{ return (bool)__x; }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(const unique_ptr<_Tp, _Dp>& __x,
|
operator<(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{
|
{
|
||||||
|
|
@ -752,67 +752,67 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
||||||
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
|
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
|
||||||
nullptr); }
|
nullptr); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
||||||
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
|
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
|
||||||
__x.get()); }
|
__x.get()); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(const unique_ptr<_Tp, _Dp>& __x,
|
operator<=(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{ return !(__y < __x); }
|
{ return !(__y < __x); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
||||||
{ return !(nullptr < __x); }
|
{ return !(nullptr < __x); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
||||||
{ return !(__x < nullptr); }
|
{ return !(__x < nullptr); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(const unique_ptr<_Tp, _Dp>& __x,
|
operator>(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{ return (__y < __x); }
|
{ return (__y < __x); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
||||||
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
|
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
|
||||||
__x.get()); }
|
__x.get()); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
||||||
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
|
{ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
|
||||||
nullptr); }
|
nullptr); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp,
|
template<typename _Tp, typename _Dp,
|
||||||
typename _Up, typename _Ep>
|
typename _Up, typename _Ep>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(const unique_ptr<_Tp, _Dp>& __x,
|
operator>=(const unique_ptr<_Tp, _Dp>& __x,
|
||||||
const unique_ptr<_Up, _Ep>& __y)
|
const unique_ptr<_Up, _Ep>& __y)
|
||||||
{ return !(__x < __y); }
|
{ return !(__x < __y); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
|
||||||
{ return !(__x < nullptr); }
|
{ return !(__x < nullptr); }
|
||||||
|
|
||||||
template<typename _Tp, typename _Dp>
|
template<typename _Tp, typename _Dp>
|
||||||
inline bool
|
_GLIBCXX_NODISCARD inline bool
|
||||||
operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
|
||||||
{ return !(nullptr < __x); }
|
{ return !(nullptr < __x); }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue