[libcxx] r299963 - Implement LWG#2873: 'Add noexcept to several shared_ptr related functions' This issue missed a couple, so I added those as well (see LWG#2942)
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 11 10:08:54 PDT 2017
Author: marshall
Date: Tue Apr 11 12:08:53 2017
New Revision: 299963
URL: http://llvm.org/viewvc/llvm-project?rev=299963&view=rev
Log:
Implement LWG#2873: 'Add noexcept to several shared_ptr related functions' This issue missed a couple, so I added those as well (see LWG#2942)
Modified:
libcxx/trunk/include/memory
libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp
libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp
libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp
libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp
libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue Apr 11 12:08:53 2017
@@ -433,8 +433,8 @@ public:
long use_count() const noexcept;
bool unique() const noexcept;
explicit operator bool() const noexcept;
- template<class U> bool owner_before(shared_ptr<U> const& b) const;
- template<class U> bool owner_before(weak_ptr<U> const& b) const;
+ template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
+ template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
// shared_ptr comparisons:
@@ -531,8 +531,8 @@ public:
long use_count() const noexcept;
bool expired() const noexcept;
shared_ptr<T> lock() const noexcept;
- template<class U> bool owner_before(shared_ptr<U> const& b) const;
- template<class U> bool owner_before(weak_ptr<U> const& b) const;
+ template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
+ template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
// weak_ptr specialized algorithms:
@@ -546,9 +546,9 @@ struct owner_less<shared_ptr<T>>
: binary_function<shared_ptr<T>, shared_ptr<T>, bool>
{
typedef bool result_type;
- bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
- bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
- bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
+ bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
+ bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+ bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
};
template<class T>
@@ -556,9 +556,24 @@ struct owner_less<weak_ptr<T>>
: binary_function<weak_ptr<T>, weak_ptr<T>, bool>
{
typedef bool result_type;
- bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
- bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
- bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
+ bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+ bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+ bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
+};
+
+template <> // Added in C++14
+struct owner_less<void>
+{
+ template <class _Tp, class _Up>
+ bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
+ template <class _Tp, class _Up>
+ bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
+ template <class _Tp, class _Up>
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
+ template <class _Tp, class _Up>
+ bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
+
+ typedef void is_transparent;
};
template<class T>
@@ -3807,11 +3822,11 @@ public:
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(shared_ptr<_Up> const& __p) const
+ bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
{return __cntrl_ < __p.__cntrl_;}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(weak_ptr<_Up> const& __p) const
+ bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
{return __cntrl_ < __p.__cntrl_;}
_LIBCPP_INLINE_VISIBILITY
bool
@@ -4907,11 +4922,11 @@ public:
shared_ptr<_Tp> lock() const _NOEXCEPT;
template<class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(const shared_ptr<_Up>& __r) const
+ bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
{return __cntrl_ < __r.__cntrl_;}
template<class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(const weak_ptr<_Up>& __r) const
+ bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
{return __cntrl_ < __r.__cntrl_;}
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
@@ -5120,13 +5135,13 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<s
{
typedef bool result_type;
_LIBCPP_INLINE_VISIBILITY
- bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
- bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
- bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
};
@@ -5136,13 +5151,13 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<w
{
typedef bool result_type;
_LIBCPP_INLINE_VISIBILITY
- bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
- bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
+ bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
- bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
};
@@ -5152,19 +5167,19 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<v
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
+ bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
+ bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
+ bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
+ bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
typedef void is_transparent;
};
Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp Tue Apr 11 12:08:53 2017
@@ -11,10 +11,11 @@
// shared_ptr
-// template <class U> bool owner_before(shared_ptr<U> const& b) const;
+// template <class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
#include <memory>
#include <cassert>
+#include "test_macros.h"
int main()
{
@@ -25,4 +26,5 @@ int main()
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
+ ASSERT_NOEXCEPT(p1.owner_before(p2));
}
Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp Tue Apr 11 12:08:53 2017
@@ -11,10 +11,11 @@
// shared_ptr
-// template <class U> bool owner_before(weak_ptr<U> const& b) const;
+// template <class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
#include <memory>
#include <cassert>
+#include "test_macros.h"
int main()
{
@@ -28,4 +29,5 @@ int main()
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
+ ASSERT_NOEXCEPT(p1.owner_before(w2));
}
Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp Tue Apr 11 12:08:53 2017
@@ -16,9 +16,9 @@
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
-// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
-// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
-// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
+// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
+// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
// };
//
// template <class T>
@@ -26,22 +26,22 @@
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
-// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
-// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
-// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
+// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
+// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
// };
//
// Added in C++17
// template<> struct owner_less<void>
// {
// template<class T, class U>
-// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const;
+// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const noexcept;
// template<class T, class U>
-// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const;
+// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const noexcept;
// template<class T, class U>
-// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const;
+// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const noexcept;
// template<class T, class U>
-// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const;
+// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const noexcept;
//
// typedef unspecified is_transparent;
// };
@@ -69,16 +69,19 @@ int main()
static_assert((std::is_same<std::shared_ptr<int>, CS::first_argument_type>::value), "" );
static_assert((std::is_same<std::shared_ptr<int>, CS::second_argument_type>::value), "" );
static_assert((std::is_same<bool, CS::result_type>::value), "" );
-
+
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
+ ASSERT_NOEXCEPT(cs(p1, p1));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
+ ASSERT_NOEXCEPT(cs(p1, w1));
+ ASSERT_NOEXCEPT(cs(w1, p1));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
@@ -92,11 +95,14 @@ int main()
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
+ ASSERT_NOEXCEPT(cs(w1, w1));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
+ ASSERT_NOEXCEPT(cs(w1, p1));
+ ASSERT_NOEXCEPT(cs(p1, w1));
}
#if TEST_STD_VER > 14
{
@@ -111,6 +117,10 @@ int main()
cmp(sp1, sp3);
cmp(wp1, sp1);
cmp(wp1, wp1);
+ ASSERT_NOEXCEPT(cmp(sp1, sp1));
+ ASSERT_NOEXCEPT(cmp(sp1, wp1));
+ ASSERT_NOEXCEPT(cmp(wp1, sp1));
+ ASSERT_NOEXCEPT(cmp(wp1, wp1));
}
{
// test heterogeneous lookups
Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp Tue Apr 11 12:08:53 2017
@@ -11,10 +11,11 @@
// weak_ptr
-// template<class U> bool owner_before(const shared_ptr<U>& b);
+// template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept;
#include <memory>
#include <cassert>
+#include "test_macros.h"
int main()
{
@@ -28,4 +29,6 @@ int main()
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
+// change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted
+ LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(p2));
}
Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp Tue Apr 11 12:08:53 2017
@@ -11,10 +11,11 @@
// weak_ptr
-// template<class U> bool owner_before(const weak_ptr<U>& b);
+// template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;
#include <memory>
#include <cassert>
+#include "test_macros.h"
int main()
{
@@ -28,4 +29,6 @@ int main()
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
+// change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted
+ LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(w2));
}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=299963&r1=299962&r2=299963&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Apr 11 12:08:53 2017
@@ -465,11 +465,11 @@
<tr><td><a href="http://wg21.link/LWG2853">2853</a></td><td>Possible inconsistency in specification of erase in [vector.modifiers]</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2855">2855</a></td><td>std::throw_with_nested("string_literal")</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2857">2857</a></td><td>{variant,optional,any}::emplace should return the constructed value</td><td>Kona</td><td></td></tr>
- <tr><td><a href="http://wg21.link/LWG2861">2861</a></td><td>basic_string should require that charT match traits::char_type</td><td>Kona</td><td>Clow</td></tr>
+ <tr><td><a href="http://wg21.link/LWG2861">2861</a></td><td>basic_string should require that charT match traits::char_type</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2866">2866</a></td><td>Incorrect derived classes constraints</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2868">2868</a></td><td>Missing specification of bad_any_cast::what()</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2872">2872</a></td><td>Add definition for direct-non-list-initialization</td><td>Kona</td><td>Complete</td></tr>
- <tr><td><a href="http://wg21.link/LWG2873">2873</a></td><td>Add noexcept to several shared_ptr related functions</td><td>Kona</td><td></td></tr>
+ <tr><td><a href="http://wg21.link/LWG2873">2873</a></td><td>Add noexcept to several shared_ptr related functions</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2874">2874</a></td><td>Constructor shared_ptr::shared_ptr(Y*) should be constrained</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2875">2875</a></td><td>shared_ptr::shared_ptr(Y*, D, […]) constructors should be constrained</td><td>Kona</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2876">2876</a></td><td>shared_ptr::shared_ptr(const weak_ptr<Y>&) constructor should be constrained</td><td>Kona</td><td></td></tr>
More information about the cfe-commits
mailing list