From 009b2c4583bcbfc5d0893154eb0866aa21b494cd Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 3 Jun 2011 15:16:49 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@132549 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__split_buffer | 4 +- include/deque | 11 ++-- .../deque.cons/default_noexcept.pass.cpp | 50 +++++++++++++++++++ .../deque/deque.cons/dtor_noexcept.pass.cpp | 48 ++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp create mode 100644 test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp diff --git a/include/__split_buffer b/include/__split_buffer index e68b7850..7c22e484 100644 --- a/include/__split_buffer +++ b/include/__split_buffer @@ -52,7 +52,8 @@ public: _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::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 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __sta template _LIBCPP_INLINE_VISIBILITY inline __split_buffer<_Tp, _Allocator>::__split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible::value) : __first_(0), __begin_(0), __end_(0), __end_cap_(0) { } diff --git a/include/deque b/include/deque index a4920598..71fa7f84 100644 --- a/include/deque +++ b/include/deque @@ -38,7 +38,7 @@ public: typedef std::reverse_iterator const_reverse_iterator; // construct/copy/destroy: - deque(); + deque() noexcept(is_nothrow_default_constructible::value); explicit deque(const allocator_type& a); explicit deque(size_type n); deque(size_type n, const value_type& v); @@ -934,7 +934,8 @@ protected: _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} - __deque_base(); + __deque_base() + _NOEXCEPT_(is_nothrow_default_constructible::value); explicit __deque_base(const allocator_type& __a); public: ~__deque_base(); @@ -1072,6 +1073,7 @@ __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT template inline _LIBCPP_INLINE_VISIBILITY __deque_base<_Tp, _Allocator>::__deque_base() + _NOEXCEPT_(is_nothrow_default_constructible::value) : __start_(0), __size_(0) {} template @@ -1185,7 +1187,10 @@ public: typedef _STD::reverse_iterator const_reverse_iterator; // construct/copy/destroy: - _LIBCPP_INLINE_VISIBILITY deque() {} + _LIBCPP_INLINE_VISIBILITY + deque() + _NOEXCEPT_(is_nothrow_default_constructible::value) + {} _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {} explicit deque(size_type __n); deque(size_type __n, const value_type& __v); diff --git a/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp b/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000..fef1bb01 --- /dev/null +++ b/test/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp @@ -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() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp b/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000..491e906b --- /dev/null +++ b/test/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp @@ -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() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +template +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 C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +}