From 7725cd74103eb408677329ec3e27657a67177833 Mon Sep 17 00:00:00 2001 From: Ole Erik Peistorpet Date: Thu, 6 Jun 2024 12:09:48 +0200 Subject: [PATCH] explicit dynarray copy constructor Also operator =(const dynarray &&) = delete --- dynarray.h | 5 +++-- unit_test/dynarray_mutate_gtest.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dynarray.h b/dynarray.h index f8ba76ff..35ccc314 100644 --- a/dynarray.h +++ b/dynarray.h @@ -101,9 +101,9 @@ class dynarray dynarray(dynarray && other) noexcept : _m(std::move(other._m)) {} dynarray(dynarray && other, Alloc a); - dynarray(const dynarray & other) : dynarray(other, + explicit dynarray(const dynarray & other) : dynarray(other, _alloTrait::select_on_container_copy_construction(other._m)) {} - dynarray(const dynarray & other, Alloc a) : _m(a) { append(other); } + explicit dynarray(const dynarray & other, Alloc a) : _m(a) { append(other); } ~dynarray() noexcept; @@ -111,6 +111,7 @@ class dynarray noexcept(_alloTrait::propagate_on_container_move_assignment::value or _alloTrait::is_always_equal::value); //! Requires that allocator_type is always equal or does not have propagate_on_container_copy_assignment dynarray & operator =(const dynarray & other) &; + dynarray & operator =(const dynarray &&) = delete; dynarray & operator =(std::initializer_list il) & { assign(il); return *this; } diff --git a/unit_test/dynarray_mutate_gtest.cpp b/unit_test/dynarray_mutate_gtest.cpp index f75eb1bb..4b18bb0d 100644 --- a/unit_test/dynarray_mutate_gtest.cpp +++ b/unit_test/dynarray_mutate_gtest.cpp @@ -831,7 +831,7 @@ TEST_F(dynarrayTest, erasePrecondCheck) leakDetector->enabled = false; dynarray di{-2}; - auto copy = di; + auto copy = dynarray(di); ASSERT_DEATH( copy.erase(di.begin()), "" ); }