noexcept for <set>.  Plus a few fixes to noexcept for <map>.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@132640 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/set b/include/set
index 7e2cdc0..0f8a19a 100644
--- a/include/set
+++ b/include/set
@@ -42,7 +42,12 @@
     typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
 
     // construct/copy/destroy:
-    explicit set(const value_compare& comp = value_compare());
+    set()
+        noexcept(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_default_constructible<key_compare>::value &&
+            is_nothrow_copy_constructible<key_compare>::value);
+    explicit set(const value_compare& comp);
     set(const value_compare& comp, const allocator_type& a);
     template <class InputIterator>
         set(InputIterator first, InputIterator last,
@@ -51,7 +56,10 @@
         set(InputIterator first, InputIterator last, const value_compare& comp,
             const allocator_type& a);
     set(const set& s);
-    set(set&& s);
+    set(set&& s)
+        noexcept(
+            is_nothrow_move_constructible<allocator_type>::value &&
+            is_nothrow_move_constructible<key_compare>::value);
     explicit set(const allocator_type& a);
     set(const set& s, const allocator_type& a);
     set(set&& s, const allocator_type& a);
@@ -61,29 +69,33 @@
     ~set();
 
     set& operator=(const set& s);
-    set& operator=(set&& s);
+    set& operator=(set&& s)
+        noexcept(
+            allocator_type::propagate_on_container_move_assignment::value &&
+            is_nothrow_move_assignable<allocator_type>::value &&
+            is_nothrow_move_assignable<key_compare>::value);
     set& operator=(initializer_list<value_type> il);
 
     // iterators:
-          iterator begin();
-    const_iterator begin() const;
-          iterator end();
-    const_iterator end()   const;
+          iterator begin() noexcept;
+    const_iterator begin() const noexcept;
+          iterator end() noexcept;
+    const_iterator end()   const noexcept;
 
-          reverse_iterator rbegin();
-    const_reverse_iterator rbegin() const;
-          reverse_iterator rend();
-    const_reverse_iterator rend()   const;
+          reverse_iterator rbegin() noexcept;
+    const_reverse_iterator rbegin() const noexcept;
+          reverse_iterator rend() noexcept;
+    const_reverse_iterator rend()   const noexcept;
 
-    const_iterator         cbegin()  const;
-    const_iterator         cend()    const;
-    const_reverse_iterator crbegin() const;
-    const_reverse_iterator crend()   const;
+    const_iterator         cbegin()  const noexcept;
+    const_iterator         cend()    const noexcept;
+    const_reverse_iterator crbegin() const noexcept;
+    const_reverse_iterator crend()   const noexcept;
 
     // capacity:
-    bool      empty()    const;
-    size_type size()     const;
-    size_type max_size() const;
+    bool      empty()    const noexcept;
+    size_type size()     const noexcept;
+    size_type max_size() const noexcept;
 
     // modifiers:
     template <class... Args>
@@ -101,12 +113,16 @@
     iterator  erase(const_iterator position);
     size_type erase(const key_type& k);
     iterator  erase(const_iterator first, const_iterator last);
-    void clear();
+    void clear() noexcept;
 
-    void swap(set& s);
+    void swap(set& s)
+        noexcept(
+            __is_nothrow_swappable<key_compare>::value &&
+            (!allocator_type::propagate_on_container_swap::value ||
+             __is_nothrow_swappable<allocator_type>::value));
 
     // observers:
-    allocator_type get_allocator() const;
+    allocator_type get_allocator() const noexcept;
     key_compare    key_comp()      const;
     value_compare  value_comp()    const;
 
@@ -155,7 +171,8 @@
 // specialized algorithms:
 template <class Key, class Compare, class Allocator>
 void
-swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y);
+swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
+    noexcept(noexcept(x.swap(y)));
 
 template <class Key, class Compare = less<Key>,
           class Allocator = allocator<Key>>
@@ -181,7 +198,12 @@
     typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
 
     // construct/copy/destroy:
-    explicit multiset(const value_compare& comp = value_compare());
+    multiset()
+        noexcept(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_default_constructible<key_compare>::value &&
+            is_nothrow_copy_constructible<key_compare>::value);
+    explicit multiset(const value_compare& comp);
     multiset(const value_compare& comp, const allocator_type& a);
     template <class InputIterator>
         multiset(InputIterator first, InputIterator last,
@@ -190,7 +212,10 @@
         multiset(InputIterator first, InputIterator last,
                  const value_compare& comp, const allocator_type& a);
     multiset(const multiset& s);
-    multiset(multiset&& s);
+    multiset(multiset&& s)
+        noexcept(
+            is_nothrow_move_constructible<allocator_type>::value &&
+            is_nothrow_move_constructible<key_compare>::value);
     explicit multiset(const allocator_type& a);
     multiset(const multiset& s, const allocator_type& a);
     multiset(multiset&& s, const allocator_type& a);
@@ -200,29 +225,33 @@
     ~multiset();
 
     multiset& operator=(const multiset& s);
-    multiset& operator=(multiset&& s);
+    multiset& operator=(multiset&& s)
+        noexcept(
+            allocator_type::propagate_on_container_move_assignment::value &&
+            is_nothrow_move_assignable<allocator_type>::value &&
+            is_nothrow_move_assignable<key_compare>::value);
     multiset& operator=(initializer_list<value_type> il);
 
     // iterators:
-          iterator begin();
-    const_iterator begin() const;
-          iterator end();
-    const_iterator end()   const;
+          iterator begin() noexcept;
+    const_iterator begin() const noexcept;
+          iterator end() noexcept;
+    const_iterator end()   const noexcept;
 
-          reverse_iterator rbegin();
-    const_reverse_iterator rbegin() const;
-          reverse_iterator rend();
-    const_reverse_iterator rend()   const;
+          reverse_iterator rbegin() noexcept;
+    const_reverse_iterator rbegin() const noexcept;
+          reverse_iterator rend() noexcept;
+    const_reverse_iterator rend()   const noexcept;
 
-    const_iterator         cbegin()  const;
-    const_iterator         cend()    const;
-    const_reverse_iterator crbegin() const;
-    const_reverse_iterator crend()   const;
+    const_iterator         cbegin()  const noexcept;
+    const_iterator         cend()    const noexcept;
+    const_reverse_iterator crbegin() const noexcept;
+    const_reverse_iterator crend()   const noexcept;
 
     // capacity:
-    bool      empty()    const;
-    size_type size()     const;
-    size_type max_size() const;
+    bool      empty()    const noexcept;
+    size_type size()     const noexcept;
+    size_type max_size() const noexcept;
 
     // modifiers:
     template <class... Args>
@@ -240,12 +269,16 @@
     iterator  erase(const_iterator position);
     size_type erase(const key_type& k);
     iterator  erase(const_iterator first, const_iterator last);
-    void clear();
+    void clear() noexcept;
 
-    void swap(multiset& s);
+    void swap(multiset& s)
+        noexcept(
+            __is_nothrow_swappable<key_compare>::value &&
+            (!allocator_type::propagate_on_container_swap::value ||
+             __is_nothrow_swappable<allocator_type>::value));
 
     // observers:
-    allocator_type get_allocator() const;
+    allocator_type get_allocator() const noexcept;
     key_compare    key_comp()      const;
     value_compare  value_comp()    const;
 
@@ -294,7 +327,8 @@
 // specialized algorithms:
 template <class Key, class Compare, class Allocator>
 void
-swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y);
+swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
+    noexcept(noexcept(x.swap(y)));
 
 }  // std
 
@@ -341,6 +375,10 @@
 
     _LIBCPP_INLINE_VISIBILITY
     explicit set(const value_compare& __comp = value_compare())
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_default_constructible<key_compare>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__comp) {}
     _LIBCPP_INLINE_VISIBILITY
     set(const value_compare& __comp, const allocator_type& __a)
@@ -373,6 +411,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     set(set&& __s)
+        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
         : __tree_(_STD::move(__s.__tree_)) {}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
@@ -416,6 +455,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     set& operator=(set&& __s)
+        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
         {
             __tree_ = _STD::move(__s.__tree_);
             return *this;
@@ -423,38 +463,42 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY
-          iterator begin()       {return __tree_.begin();}
+          iterator begin() _NOEXCEPT       {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator begin() const {return __tree_.begin();}
+    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
-          iterator end()         {return __tree_.end();}
+          iterator end() _NOEXCEPT         {return __tree_.end();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator end()   const {return __tree_.end();}
+    const_iterator end()   const _NOEXCEPT {return __tree_.end();}
 
     _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+          reverse_iterator rbegin() _NOEXCEPT
+            {return reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+    const_reverse_iterator rbegin() const _NOEXCEPT
+        {return const_reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rend()         {return       reverse_iterator(begin());}
+          reverse_iterator rend() _NOEXCEPT
+            {return reverse_iterator(begin());}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+    const_reverse_iterator rend() const _NOEXCEPT
+        {return const_reverse_iterator(begin());}
 
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator         cbegin()  const {return begin();}
+    const_iterator cbegin()  const _NOEXCEPT {return begin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator         cend()    const {return end();}
+    const_iterator cend() const _NOEXCEPT {return end();}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator crend()   const {return rend();}
+    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
 
     _LIBCPP_INLINE_VISIBILITY
-    bool      empty()    const {return __tree_.size() == 0;}
+    bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
     _LIBCPP_INLINE_VISIBILITY
-    size_type size()     const {return __tree_.size();}
+    size_type size() const _NOEXCEPT {return __tree_.size();}
     _LIBCPP_INLINE_VISIBILITY
-    size_type max_size() const {return __tree_.max_size();}
+    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
 
     // modifiers:
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -504,13 +548,14 @@
     iterator  erase(const_iterator __f, const_iterator __l)
         {return __tree_.erase(__f, __l);}
     _LIBCPP_INLINE_VISIBILITY
-    void clear() {__tree_.clear();}
+    void clear() _NOEXCEPT {__tree_.clear();}
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(set& __s) {__tree_.swap(__s.__tree_);}
+    void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
+        {__tree_.swap(__s.__tree_);}
 
     _LIBCPP_INLINE_VISIBILITY
-    allocator_type get_allocator() const {return __tree_.__alloc();}
+    allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
     _LIBCPP_INLINE_VISIBILITY
     key_compare    key_comp()      const {return __tree_.value_comp();}
     _LIBCPP_INLINE_VISIBILITY
@@ -620,6 +665,7 @@
 void
 swap(set<_Key, _Compare, _Allocator>& __x,
      set<_Key, _Compare, _Allocator>& __y)
+    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
     __x.swap(__y);
 }
@@ -658,6 +704,10 @@
     // construct/copy/destroy:
     _LIBCPP_INLINE_VISIBILITY
     explicit multiset(const value_compare& __comp = value_compare())
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<allocator_type>::value &&
+            is_nothrow_default_constructible<key_compare>::value &&
+            is_nothrow_copy_constructible<key_compare>::value)
         : __tree_(__comp) {}
     _LIBCPP_INLINE_VISIBILITY
     multiset(const value_compare& __comp, const allocator_type& __a)
@@ -691,6 +741,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     multiset(multiset&& __s)
+        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
         : __tree_(_STD::move(__s.__tree_)) {}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
@@ -731,6 +782,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     multiset& operator=(multiset&& __s)
+        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
         {
             __tree_ = _STD::move(__s.__tree_);
             return *this;
@@ -738,38 +790,42 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY
-          iterator begin()       {return __tree_.begin();}
+          iterator begin() _NOEXCEPT       {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator begin() const {return __tree_.begin();}
+    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
-          iterator end()         {return __tree_.end();}
+          iterator end() _NOEXCEPT         {return __tree_.end();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator end()   const {return __tree_.end();}
+    const_iterator end()   const _NOEXCEPT {return __tree_.end();}
 
     _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+          reverse_iterator rbegin() _NOEXCEPT
+            {return reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+    const_reverse_iterator rbegin() const _NOEXCEPT
+        {return const_reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rend()         {return       reverse_iterator(begin());}
+          reverse_iterator rend() _NOEXCEPT
+            {return       reverse_iterator(begin());}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+    const_reverse_iterator rend() const _NOEXCEPT
+        {return const_reverse_iterator(begin());}
 
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator         cbegin()  const {return begin();}
+    const_iterator cbegin()  const _NOEXCEPT {return begin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_iterator         cend()    const {return end();}
+    const_iterator cend() const _NOEXCEPT {return end();}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
     _LIBCPP_INLINE_VISIBILITY
-    const_reverse_iterator crend()   const {return rend();}
+    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
 
     _LIBCPP_INLINE_VISIBILITY
-    bool      empty()    const {return __tree_.size() == 0;}
+    bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
     _LIBCPP_INLINE_VISIBILITY
-    size_type size()     const {return __tree_.size();}
+    size_type size() const _NOEXCEPT {return __tree_.size();}
     _LIBCPP_INLINE_VISIBILITY
-    size_type max_size() const {return __tree_.max_size();}
+    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
 
     // modifiers:
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -818,13 +874,15 @@
     iterator  erase(const_iterator __f, const_iterator __l)
         {return __tree_.erase(__f, __l);}
     _LIBCPP_INLINE_VISIBILITY
-    void clear() {__tree_.clear();}
+    void clear() _NOEXCEPT {__tree_.clear();}
 
     _LIBCPP_INLINE_VISIBILITY
-    void swap(multiset& __s) {__tree_.swap(__s.__tree_);}
+    void swap(multiset& __s)
+        _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
+        {__tree_.swap(__s.__tree_);}
 
     _LIBCPP_INLINE_VISIBILITY
-    allocator_type get_allocator() const {return __tree_.__alloc();}
+    allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
     _LIBCPP_INLINE_VISIBILITY
     key_compare    key_comp()      const {return __tree_.value_comp();}
     _LIBCPP_INLINE_VISIBILITY
@@ -933,6 +991,7 @@
 void
 swap(multiset<_Key, _Compare, _Allocator>& __x,
      multiset<_Key, _Compare, _Allocator>& __y)
+    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
     __x.swap(__y);
 }