[cfe-commits] [libcxx] r132549 - in /libcxx/trunk: include/__split_buffer include/deque test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp

Howard Hinnant hhinnant at apple.com
Fri Jun 3 08:16:50 PDT 2011


Author: hhinnant
Date: Fri Jun  3 10:16:49 2011
New Revision: 132549

URL: http://llvm.org/viewvc/llvm-project?rev=132549&view=rev
Log:
After sleeping on it I've decided that all special members that can be noexcept, should be declared so.  The client has the traits to detect and branch on this information, and it is often an important optimization.  Give deque() a noexcept.  Add test for deque default constructor and deque destructor.

Added:
    libcxx/trunk/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp
    libcxx/trunk/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp
Modified:
    libcxx/trunk/include/__split_buffer
    libcxx/trunk/include/deque

Modified: libcxx/trunk/include/__split_buffer
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__split_buffer?rev=132549&r1=132548&r2=132549&view=diff
==============================================================================
--- libcxx/trunk/include/__split_buffer (original)
+++ libcxx/trunk/include/__split_buffer Fri Jun  3 10:16:49 2011
@@ -52,7 +52,8 @@
     _LIBCPP_INLINE_VISIBILITY pointer&              __end_cap() _NOEXCEPT       {return __end_cap_.first();}
     _LIBCPP_INLINE_VISIBILITY const pointer&        __end_cap() const _NOEXCEPT {return __end_cap_.first();}
 
-    __split_buffer();
+    __split_buffer()
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
     explicit __split_buffer(__alloc_rr& __a);
     explicit __split_buffer(const __alloc_rr& __a);
     __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
@@ -323,6 +324,7 @@
 template <class _Tp, class _Allocator>
 _LIBCPP_INLINE_VISIBILITY inline
 __split_buffer<_Tp, _Allocator>::__split_buffer()
+    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
     : __first_(0), __begin_(0), __end_(0), __end_cap_(0)
 {
 }

Modified: libcxx/trunk/include/deque
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=132549&r1=132548&r2=132549&view=diff
==============================================================================
--- libcxx/trunk/include/deque (original)
+++ libcxx/trunk/include/deque Fri Jun  3 10:16:49 2011
@@ -38,7 +38,7 @@
     typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
 
     // construct/copy/destroy:
-    deque();
+    deque() noexcept(is_nothrow_default_constructible<allocator_type>::value);
     explicit deque(const allocator_type& a);
     explicit deque(size_type n);
     deque(size_type n, const value_type& v);
@@ -934,7 +934,8 @@
     _LIBCPP_INLINE_VISIBILITY
     const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
 
-    __deque_base();
+    __deque_base()
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
     explicit __deque_base(const allocator_type& __a);
 public:
     ~__deque_base();
@@ -1072,6 +1073,7 @@
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 __deque_base<_Tp, _Allocator>::__deque_base()
+    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
     : __start_(0), __size_(0) {}
 
 template <class _Tp, class _Allocator>
@@ -1185,7 +1187,10 @@
     typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
 
     // construct/copy/destroy:
-    _LIBCPP_INLINE_VISIBILITY deque() {}
+    _LIBCPP_INLINE_VISIBILITY
+    deque()
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
+        {}
     _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {}
     explicit deque(size_type __n);
     deque(size_type __n, const value_type& __v);

Added: libcxx/trunk/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp?rev=132549&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp Fri Jun  3 10:16:49 2011
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// deque()
+//        noexcept(is_nothrow_default_constructible<allocator_type>::value);
+
+// This tests a conforming extension
+
+#include <deque>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+#include "../../../test_allocator.h"
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+};
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::deque<MoveOnly> C;
+        static_assert(std::is_nothrow_default_constructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C;
+        static_assert(std::is_nothrow_default_constructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C;
+        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C;
+        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp?rev=132549&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp Fri Jun  3 10:16:49 2011
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// ~deque() // implied noexcept;
+
+#include <deque>
+#include <cassert>
+
+#include "../../../MoveOnly.h"
+#include "../../../test_allocator.h"
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+    ~some_alloc() noexcept(false);
+};
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::deque<MoveOnly> C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+    {
+        typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C;
+        static_assert(!std::is_nothrow_destructible<C>::value, "");
+    }
+#endif
+}





More information about the cfe-commits mailing list