From 8229aa6b3ce875d8c4738ecee7cbeee43bc53961 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 23 Apr 2017 10:51:17 +0100 Subject: [PATCH] Stop throwing exception in allocator copy/assignment The standard specifies that all of these "shall not exit via an exception". The containers have been exception safe when these throw, but the 'noexcept' attribute on 'get_allocator' will terminate if an exception is thrown in the copy constructor. The standard doesn't specify a default constructor, so that is allowed to throw an exception (not just pedantry, this makes sense if an allocator has shared data that's allocated in the initial constructor). --- test/objects/exception.hpp | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index d5f0f5db..e76ac477 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -339,19 +339,11 @@ template class allocator template allocator(allocator const& x) : tag_(x.tag_) { - UNORDERED_SCOPE(allocator::allocator()) - { - UNORDERED_EPOINT("Mock allocator template copy constructor."); - } test::detail::tracker.allocator_ref(); } allocator(allocator const& x) : tag_(x.tag_) { - UNORDERED_SCOPE(allocator::allocator()) - { - UNORDERED_EPOINT("Mock allocator copy constructor."); - } test::detail::tracker.allocator_ref(); } @@ -359,11 +351,7 @@ template class allocator allocator& operator=(allocator const& x) { - UNORDERED_SCOPE(allocator::allocator()) - { - UNORDERED_EPOINT("Mock allocator assignment operator."); - tag_ = x.tag_; - } + tag_ = x.tag_; return *this; } @@ -530,42 +518,22 @@ template class allocator2 allocator2(allocator const& x) : tag_(x.tag_) { - UNORDERED_SCOPE(allocator2::allocator2()) - { - UNORDERED_EPOINT("Mock allocator2 constructor from allocator."); - } test::detail::tracker.allocator_ref(); } template allocator2(allocator2 const& x) : tag_(x.tag_) { - UNORDERED_SCOPE(allocator2::allocator2()) - { - UNORDERED_EPOINT("Mock allocator2 template copy constructor."); - } test::detail::tracker.allocator_ref(); } allocator2(allocator2 const& x) : tag_(x.tag_) { - UNORDERED_SCOPE(allocator2::allocator2()) - { - UNORDERED_EPOINT("Mock allocator2 copy constructor."); - } test::detail::tracker.allocator_ref(); } ~allocator2() { test::detail::tracker.allocator_unref(); } - allocator2& operator=(allocator2 const& x) - { - UNORDERED_SCOPE(allocator2::allocator2()) - { - UNORDERED_EPOINT("Mock allocator2 assignment operator."); - tag_ = x.tag_; - } - return *this; - } + allocator2& operator=(allocator2 const&) { return *this; } // If address throws, then it can't be used in erase or the // destructor, which is very limiting. I need to check up on