Эх сурвалжийг харах

noexcept for <memory>. I've added a few extension noexcept to: allocator_traits<A>::deallocate, allocaate<T>::deallocate, return_temporary_buffer, and default_delete<T>::operator()(T*) const. My rationale was: If a std-dicated noexcept function needs to call another std-defined function, that called function must be noexcept. We're all a little new to noexcept, so things like this are to be expected. Also included fix for broken __is_swappable trait pointed out by Marc Glisse, thanks Marc|. And fixed a test case for is_nothrow_destructible. Destructors are now noexcept by default|

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@132261 91177308-0d34-0410-b5e6-96231b3b80d8
Howard Hinnant 14 жил өмнө
parent
commit
1694d23e23

+ 1 - 1
include/__locale

@@ -103,7 +103,7 @@ protected:
 //    facet(const facet&) = delete;     // effectively done in __shared_count
 //    void operator=(const facet&) = delete;
 private:
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 };
 
 class _LIBCPP_VISIBLE locale::id

+ 15 - 15
include/future

@@ -463,7 +463,7 @@ protected:
     mutable condition_variable __cv_;
     unsigned __state_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
     void __sub_wait(unique_lock<mutex>& __lk);
 public:
     enum
@@ -543,7 +543,7 @@ class __assoc_state
 protected:
     _U __value_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
 
     template <class _Arg>
@@ -566,7 +566,7 @@ public:
 
 template <class _R>
 void
-__assoc_state<_R>::__on_zero_shared()
+__assoc_state<_R>::__on_zero_shared() _NOEXCEPT
 {
     if (this->__state_ & base::__constructed)
         reinterpret_cast<_R*>(&__value_)->~_R();
@@ -640,7 +640,7 @@ class __assoc_state<_R&>
 protected:
     _U __value_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
 
     void set_value(_R& __arg);
@@ -651,7 +651,7 @@ public:
 
 template <class _R>
 void
-__assoc_state<_R&>::__on_zero_shared()
+__assoc_state<_R&>::__on_zero_shared() _NOEXCEPT
 {
     delete this;
 }
@@ -700,7 +700,7 @@ class __assoc_state_alloc
     typedef __assoc_state<_R> base;
     _Alloc __alloc_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
     _LIBCPP_INLINE_VISIBILITY
     explicit __assoc_state_alloc(const _Alloc& __a)
@@ -709,7 +709,7 @@ public:
 
 template <class _R, class _Alloc>
 void
-__assoc_state_alloc<_R, _Alloc>::__on_zero_shared()
+__assoc_state_alloc<_R, _Alloc>::__on_zero_shared() _NOEXCEPT
 {
     if (this->__state_ & base::__constructed)
         reinterpret_cast<_R*>(&this->__value_)->~_R();
@@ -725,7 +725,7 @@ class __assoc_state_alloc<_R&, _Alloc>
     typedef __assoc_state<_R&> base;
     _Alloc __alloc_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
     _LIBCPP_INLINE_VISIBILITY
     explicit __assoc_state_alloc(const _Alloc& __a)
@@ -734,7 +734,7 @@ public:
 
 template <class _R, class _Alloc>
 void
-__assoc_state_alloc<_R&, _Alloc>::__on_zero_shared()
+__assoc_state_alloc<_R&, _Alloc>::__on_zero_shared() _NOEXCEPT
 {
     typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
     this->~__assoc_state_alloc();
@@ -748,7 +748,7 @@ class __assoc_sub_state_alloc
     typedef __assoc_sub_state base;
     _Alloc __alloc_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
     _LIBCPP_INLINE_VISIBILITY
     explicit __assoc_sub_state_alloc(const _Alloc& __a)
@@ -757,7 +757,7 @@ public:
 
 template <class _Alloc>
 void
-__assoc_sub_state_alloc<_Alloc>::__on_zero_shared()
+__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
 {
     this->~base();
     typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_);
@@ -866,7 +866,7 @@ class __async_assoc_state
 
     _F __func_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     explicit __async_assoc_state(_F&& __f);
@@ -906,7 +906,7 @@ __async_assoc_state<_R, _F>::__execute()
 
 template <class _R, class _F>
 void
-__async_assoc_state<_R, _F>::__on_zero_shared()
+__async_assoc_state<_R, _F>::__on_zero_shared() _NOEXCEPT
 {
     this->wait();
     base::__on_zero_shared();
@@ -920,7 +920,7 @@ class __async_assoc_state<void, _F>
 
     _F __func_;
 
-    virtual void __on_zero_shared();
+    virtual void __on_zero_shared() _NOEXCEPT;
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     explicit __async_assoc_state(_F&& __f);
@@ -961,7 +961,7 @@ __async_assoc_state<void, _F>::__execute()
 
 template <class _F>
 void
-__async_assoc_state<void, _F>::__on_zero_shared()
+__async_assoc_state<void, _F>::__on_zero_shared() _NOEXCEPT
 {
     this->wait();
     base::__on_zero_shared();

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 291 - 180
include/memory


+ 12 - 2
include/type_traits

@@ -2999,7 +2999,11 @@ struct __invoke_of
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-void
+typename enable_if
+<
+    is_move_constructible<_Tp>::value &&
+    is_move_assignable<_Tp>::value
+>::type
 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
                                     is_nothrow_move_assignable<_Tp>::value)
 {
@@ -3021,6 +3025,10 @@ iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
 
 // __swappable
 
+namespace __detail
+{
+
+using _STD::swap;
 __nat swap(__any, __any);
 
 template <class _Tp>
@@ -3030,9 +3038,11 @@ struct __swappable
     static const bool value = !is_same<type, __nat>::value;
 };
 
+}  // __detail
+
 template <class _Tp>
 struct __is_swappable
-    : public integral_constant<bool, __swappable<_Tp>::value>
+    : public integral_constant<bool, __detail::__swappable<_Tp>::value>
 {
 };
 

+ 1 - 1
src/future.cpp

@@ -60,7 +60,7 @@ future_error::future_error(error_code __ec)
 }
 
 void
-__assoc_sub_state::__on_zero_shared()
+__assoc_sub_state::__on_zero_shared() _NOEXCEPT
 {
     delete this;
 }

+ 1 - 1
src/locale.cpp

@@ -518,7 +518,7 @@ locale::facet::~facet()
 }
 
 void
-locale::facet::__on_zero_shared()
+locale::facet::__on_zero_shared() _NOEXCEPT
 {
     delete this;
 }

+ 13 - 13
src/memory.cpp

@@ -16,14 +16,14 @@ namespace
 
 template <class T>
 inline T
-increment(T& t)
+increment(T& t) _NOEXCEPT
 {
     return __sync_add_and_fetch(&t, 1);
 }
 
 template <class T>
 inline T
-decrement(T& t)
+decrement(T& t) _NOEXCEPT
 {
     return __sync_add_and_fetch(&t, -1);
 }
@@ -32,10 +32,10 @@ decrement(T& t)
 
 const allocator_arg_t allocator_arg = allocator_arg_t();
 
-bad_weak_ptr::~bad_weak_ptr() throw() {}
+bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {}
 
 const char*
-bad_weak_ptr::what() const throw()
+bad_weak_ptr::what() const _NOEXCEPT
 {
     return "bad_weak_ptr";
 }
@@ -45,13 +45,13 @@ __shared_count::~__shared_count()
 }
 
 void
-__shared_count::__add_shared()
+__shared_count::__add_shared() _NOEXCEPT
 {
     increment(__shared_owners_);
 }
 
 bool
-__shared_count::__release_shared()
+__shared_count::__release_shared() _NOEXCEPT
 {
     if (decrement(__shared_owners_) == -1)
     {
@@ -66,33 +66,33 @@ __shared_weak_count::~__shared_weak_count()
 }
 
 void
-__shared_weak_count::__add_shared()
+__shared_weak_count::__add_shared() _NOEXCEPT
 {
     __shared_count::__add_shared();
 }
 
 void
-__shared_weak_count::__add_weak()
+__shared_weak_count::__add_weak() _NOEXCEPT
 {
     increment(__shared_weak_owners_);
 }
 
 void
-__shared_weak_count::__release_shared()
+__shared_weak_count::__release_shared() _NOEXCEPT
 {
     if (__shared_count::__release_shared())
         __release_weak();
 }
 
 void
-__shared_weak_count::__release_weak()
+__shared_weak_count::__release_weak() _NOEXCEPT
 {
     if (decrement(__shared_weak_owners_) == -1)
         __on_zero_shared_weak();
 }
 
 __shared_weak_count*
-__shared_weak_count::lock()
+__shared_weak_count::lock() _NOEXCEPT
 {
     long object_owners = __shared_owners_;
     while (object_owners != -1)
@@ -112,7 +112,7 @@ __shared_weak_count::lock()
 #ifndef _LIBCPP_NO_RTTI
 
 const void*
-__shared_weak_count::__get_deleter(const type_info&) const
+__shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
 {
     return 0;
 }
@@ -135,7 +135,7 @@ undeclare_no_pointers(char*, size_t)
 }
 
 pointer_safety
-get_pointer_safety()
+get_pointer_safety() _NOEXCEPT
 {
     return pointer_safety::relaxed;
 }

+ 1 - 1
test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp

@@ -60,10 +60,10 @@ struct A
 int main()
 {
     test_has_not_nothrow_destructor<void>();
-    test_has_not_nothrow_destructor<A>();
     test_has_not_nothrow_destructor<Abstract>();
     test_has_not_nothrow_destructor<NotEmpty>();
 
+    test_is_nothrow_destructible<A>();
     test_is_nothrow_destructible<int&>();
     test_is_nothrow_destructible<Union>();
     test_is_nothrow_destructible<Empty>();

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно