[cfe-commits] [libcxx] r132652 - in /libcxx/trunk: include/stack test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp

Howard Hinnant hhinnant at apple.com
Sat Jun 4 15:09:19 PDT 2011


Author: hhinnant
Date: Sat Jun  4 17:09:19 2011
New Revision: 132652

URL: http://llvm.org/viewvc/llvm-project?rev=132652&view=rev
Log:
noexcept for <stack>.  This completes noexcept for Chapter 23 [containers].

Added:
    libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp
    libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp
    libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp
    libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp
    libcxx/trunk/test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp
Modified:
    libcxx/trunk/include/stack

Modified: libcxx/trunk/include/stack
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stack?rev=132652&r1=132651&r2=132652&view=diff
==============================================================================
--- libcxx/trunk/include/stack (original)
+++ libcxx/trunk/include/stack Sat Jun  4 17:09:19 2011
@@ -31,14 +31,21 @@
     container_type c;
 
 public:
-    explicit stack();
+    stack() = default;
+    ~stack() = default;
+
+    stack(const stack& q) = default;
+    stack(stack&& q) = default;
+
+    stack& operator=(const stack& q) = default;
+    stack& operator=(stack&& q) = default;
+
     explicit stack(const container_type& c);
     explicit stack(container_type&& c);
-    stack(stack&& s);
-    stack& operator=(stack&& s);
     template <class Alloc> explicit stack(const Alloc& a);
     template <class Alloc> stack(const container_type& c, const Alloc& a);
     template <class Alloc> stack(container_type&& c, const Alloc& a);
+    template <class Alloc> stack(const stack& c, const Alloc& a);
     template <class Alloc> stack(stack&& c, const Alloc& a);
 
     bool empty() const;
@@ -51,7 +58,7 @@
     template <class... Args> void emplace(Args&&... args);
     void pop();
 
-    void swap(stack& c);
+    void swap(stack& c) noexcept(noexcept(swap(c, q.c)));
 };
 
 template <class T, class Container>
@@ -68,7 +75,8 @@
   bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
 
 template <class T, class Container>
-  void swap(stack<T, Container>& x, stack<T, Container>& y);
+  void swap(stack<T, Container>& x, stack<T, Container>& y)
+  noexcept(noexcept(x.swap(y)));
 
 }  // std
 
@@ -106,16 +114,35 @@
 
 public:
     _LIBCPP_INLINE_VISIBILITY
-    stack() : c() {}
+    stack()
+        _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
+        : c() {}
+
     _LIBCPP_INLINE_VISIBILITY
-    explicit stack(const container_type& __c) : c(__c) {}
+    stack(const stack& __q) : c(__q.c) {}
+
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    explicit stack(container_type&& __c) : c(_STD::move(__c)) {}
+    stack(stack&& __q)
+        _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
+        : c(_STD::move(__q.c)) {}
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
     _LIBCPP_INLINE_VISIBILITY
-    stack(stack&& __s) : c(_STD::move(__s.c)) {}
+    stack& operator=(const stack& __q) {c = __q.c; return *this;}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    _LIBCPP_INLINE_VISIBILITY
+    stack& operator=(stack&& __q)
+        _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
+        {c = _STD::move(__q.c); return *this;}
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
     _LIBCPP_INLINE_VISIBILITY
-    stack& operator=(stack&& __s) {c = _STD::move(__s.c); return *this;}
+    explicit stack(const container_type& __c) : c(__c) {}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    _LIBCPP_INLINE_VISIBILITY
+    explicit stack(container_type&& __c) : c(_STD::move(__c)) {}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _Alloc>
         _LIBCPP_INLINE_VISIBILITY
@@ -176,6 +203,7 @@
 
     _LIBCPP_INLINE_VISIBILITY
     void swap(stack& __s)
+        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
     {
         using _STD::swap;
         swap(c, __s.c);
@@ -244,6 +272,7 @@
 inline _LIBCPP_INLINE_VISIBILITY
 void
 swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
+    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
     __x.swap(__y);
 }

Added: libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp?rev=132652&view=auto
==============================================================================
--- libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp Sat Jun  4 17:09:19 2011
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <stack>
+
+// stack()
+//        noexcept(is_nothrow_default_constructible<container_type>::value);
+
+// This tests a conforming extension
+
+#include <stack>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::stack<MoveOnly> C;
+        static_assert(std::is_nothrow_default_constructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp?rev=132652&view=auto
==============================================================================
--- libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp Sat Jun  4 17:09:19 2011
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <stack>
+
+// ~stack() // implied noexcept;
+
+#include <stack>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::stack<MoveOnly> C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp?rev=132652&view=auto
==============================================================================
--- libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp Sat Jun  4 17:09:19 2011
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <stack>
+
+// stack& operator=(stack&& c)
+//     noexcept(is_nothrow_move_assignable<container_type>::value);
+
+// This tests a conforming extension
+
+#include <stack>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::stack<MoveOnly> C;
+        static_assert(std::is_nothrow_move_assignable<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp?rev=132652&view=auto
==============================================================================
--- libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp Sat Jun  4 17:09:19 2011
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <stack>
+
+// stack(stack&&)
+//        noexcept(is_nothrow_move_constructible<container_type>::value);
+
+// This tests a conforming extension
+
+#include <stack>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::stack<MoveOnly> C;
+        static_assert(std::is_nothrow_move_constructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp?rev=132652&view=auto
==============================================================================
--- libcxx/trunk/test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp Sat Jun  4 17:09:19 2011
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <stack>
+
+// void swap(stack& c)
+//     noexcept(__is_nothrow_swappable<container_type>::value);
+
+// This tests a conforming extension
+
+#include <stack>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::stack<MoveOnly> C;
+        C c1, c2;
+        static_assert(noexcept(swap(c1, c2)), "");
+    }
+#endif
+}





More information about the cfe-commits mailing list