From 6971d82668f88a48aaa9373d22728069e454b82c Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 4 Jun 2011 21:32:33 +0000 Subject: [PATCH] noexcept for . llvm-svn: 132650 --- libcxx/include/queue | 135 ++++++++++++------ .../priqueue.cons/default_noexcept.pass.cpp | 31 ++++ .../priqueue.cons/dtor_noexcept.pass.cpp | 27 ++++ .../move_assign_noexcept.pass.cpp | 31 ++++ .../priqueue.cons/move_noexcept.pass.cpp | 31 ++++ .../priqueue.special/swap_noexcept.pass.cpp | 32 +++++ .../queue.cons/default_noexcept.pass.cpp | 30 ++++ .../queue/queue.cons/dtor_noexcept.pass.cpp | 27 ++++ .../queue.cons/move_assign_noexcept.pass.cpp | 30 ++++ .../queue/queue.cons/move_noexcept.pass.cpp | 30 ++++ .../queue.special/swap_noexcept.pass.cpp | 31 ++++ 11 files changed, 393 insertions(+), 42 deletions(-) create mode 100644 libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp diff --git a/libcxx/include/queue b/libcxx/include/queue index f2e5d30034df..896c68265ac0 100644 --- a/libcxx/include/queue +++ b/libcxx/include/queue @@ -31,21 +31,28 @@ protected: container_type c; public: - queue(); + queue() = default; + ~queue() = default; + + queue(const queue& q) = default; + queue(queue&& q) = default; + + queue& operator=(const queue& q) = default; + queue& operator=(queue&& q) = default; + explicit queue(const container_type& c); - explicit queue(container_type&& c); - queue(queue&& q); + explicit queue(container_type&& c) template explicit queue(const Alloc& a); template queue(const container_type& c, const Alloc& a); template queue(container_type&& c, const Alloc& a); + template + queue(const queue& q, const Alloc& a); template queue(queue&& q, const Alloc& a); - queue& operator=(queue&& q); - bool empty() const; size_type size() const; @@ -59,7 +66,7 @@ public: template void emplace(Args&&... args); void pop(); - void swap(queue& q); + void swap(queue& q) noexcept(noexcept(swap(c, q.c))); }; template @@ -81,7 +88,8 @@ template bool operator<=(const queue& x,const queue& y); template - void swap(queue& x, queue& y); + void swap(queue& x, queue& y) + noexcept(noexcept(x.swap(y))); template , class Compare = less> @@ -99,7 +107,16 @@ protected: Compare comp; public: - explicit priority_queue(const Compare& comp = Compare()); + priority_queue() = default; + ~priority_queue() = default; + + priority_queue(const priority_queue& q) = default; + priority_queue(priority_queue&& q) = default; + + priority_queue& operator=(const priority_queue& q) = default; + priority_queue& operator=(priority_queue&& q) = default; + + explicit priority_queue(const Compare& comp); priority_queue(const Compare& comp, const container_type& c); explicit priority_queue(const Compare& comp, container_type&& c); template @@ -111,8 +128,6 @@ public: template priority_queue(InputIterator first, InputIterator last, const Compare& comp, container_type&& c); - priority_queue(priority_queue&& q); - priority_queue& operator=(priority_queue&& q); template explicit priority_queue(const Alloc& a); template @@ -123,6 +138,8 @@ public: template priority_queue(const Compare& comp, container_type&& c, const Alloc& a); + template + priority_queue(const priority_queue& q, const Alloc& a); template priority_queue(priority_queue&& q, const Alloc& a); @@ -135,12 +152,14 @@ public: template void emplace(Args&&... args); void pop(); - void swap(priority_queue& q); + void swap(priority_queue& q) + noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp))); }; template void swap(priority_queue& x, - priority_queue& y); + priority_queue& y) + noexcept(noexcept(x.swap(y))); } // std @@ -181,14 +200,35 @@ protected: public: _LIBCPP_INLINE_VISIBILITY - queue() : c() {} + queue() + _NOEXCEPT_(is_nothrow_default_constructible::value) + : c() {} + + _LIBCPP_INLINE_VISIBILITY + queue(const queue& __q) : c(__q.c) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + queue(queue&& __q) + _NOEXCEPT_(is_nothrow_move_constructible::value) + : c(_STD::move(__q.c)) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + queue& operator=(const queue& __q) {c = __q.c; return *this;} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + queue& operator=(queue&& __q) + _NOEXCEPT_(is_nothrow_move_assignable::value) + {c = _STD::move(__q.c); return *this;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY explicit queue(const container_type& __c) : c(__c) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY explicit queue(container_type&& __c) : c(_STD::move(__c)) {} - _LIBCPP_INLINE_VISIBILITY - queue(queue&& __q) : c(_STD::move(__q.c)) {} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template _LIBCPP_INLINE_VISIBILITY @@ -222,12 +262,6 @@ public: _Alloc>::value>::type* = 0) : c(_STD::move(__q.c), __a) {} - _LIBCPP_INLINE_VISIBILITY - queue& operator=(queue&& __q) - { - c = _STD::move(__q.c); - return *this; - } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY @@ -261,6 +295,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(queue& __q) + _NOEXCEPT_(__is_nothrow_swappable::value) { using _STD::swap; swap(c, __q.c); @@ -331,6 +366,7 @@ template inline _LIBCPP_INLINE_VISIBILITY void swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } @@ -359,7 +395,36 @@ protected: public: _LIBCPP_INLINE_VISIBILITY - explicit priority_queue(const value_compare& __comp = value_compare()) + priority_queue() + _NOEXCEPT_(is_nothrow_default_constructible::value && + is_nothrow_default_constructible::value) + : c(), comp() {} + + _LIBCPP_INLINE_VISIBILITY + priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + priority_queue(priority_queue&& __q) + _NOEXCEPT_(is_nothrow_move_constructible::value && + is_nothrow_move_constructible::value) + : c(_STD::move(__q.c)), comp(_STD::move(__q.comp)) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + priority_queue& operator=(const priority_queue& __q) + {c = __q.c; comp = __q.comp; return *this;} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + priority_queue& operator=(priority_queue&& __q) + _NOEXCEPT_(is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) + {c = _STD::move(__q.c); comp = _STD::move(__q.comp); return *this;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {} priority_queue(const value_compare& __comp, const container_type& __c); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -375,8 +440,6 @@ public: template priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c); - priority_queue(priority_queue&& __q); - priority_queue& operator=(priority_queue&& __q); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template explicit priority_queue(const _Alloc& __a, @@ -423,7 +486,9 @@ public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES void pop(); - void swap(priority_queue& __q); + void swap(priority_queue& __q) + _NOEXCEPT_(__is_nothrow_swappable::value && + __is_nothrow_swappable::value); }; template @@ -489,23 +554,6 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input _STD::make_heap(c.begin(), c.end(), comp); } -template -inline _LIBCPP_INLINE_VISIBILITY -priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q) - : c(_STD::move(__q.c)), - comp(_STD::move(__q.comp)) -{ -} - -template -priority_queue<_Tp, _Container, _Compare>& -priority_queue<_Tp, _Container, _Compare>::operator=(priority_queue&& __q) -{ - c = _STD::move(__q.c); - comp = _STD::move(__q.comp); - return *this; -} - #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template @@ -636,6 +684,8 @@ template inline _LIBCPP_INLINE_VISIBILITY void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q) + _NOEXCEPT_(__is_nothrow_swappable::value && + __is_nothrow_swappable::value) { using _STD::swap; swap(c, __q.c); @@ -647,6 +697,7 @@ inline _LIBCPP_INLINE_VISIBILITY void swap(priority_queue<_Tp, _Container, _Compare>& __x, priority_queue<_Tp, _Container, _Compare>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } diff --git a/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp new file mode 100644 index 000000000000..48e075698ad3 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue() +// noexcept(is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp new file mode 100644 index 000000000000..80ad8bdb28be --- /dev/null +++ b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// ~priority_queue() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 000000000000..7fd01d6dcb68 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue& operator=(priority_queue&& c) +// noexcept(is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp new file mode 100644 index 000000000000..1e7fcd86b469 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(priority_queue&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp new file mode 100644 index 000000000000..e40570a120ba --- /dev/null +++ b/libcxx/test/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(priority_queue& c) +// noexcept(__is_nothrow_swappable::value && +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp new file mode 100644 index 000000000000..874577c76325 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// queue() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp new file mode 100644 index 000000000000..1af20ecb04bb --- /dev/null +++ b/libcxx/test/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// ~queue() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 000000000000..1b45bfa93ee7 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// queue& operator=(queue&& c) +// noexcept(is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp new file mode 100644 index 000000000000..8fba28fc5349 --- /dev/null +++ b/libcxx/test/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// queue(queue&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp b/libcxx/test/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp new file mode 100644 index 000000000000..5c9b7756b8ae --- /dev/null +++ b/libcxx/test/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(queue& c) +// noexcept(__is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +}