electronicarts / EASTL

EASTL stands for Electronic Arts Standard Template Library. It is an extensive and robust implementation that has an emphasis on high performance.
BSD 3-Clause "New" or "Revised" License
7.82k stars 905 forks source link

Incorrect behaviour of vector (and other) with switched off exceptions #485

Open AntonYudintsev opened 1 year ago

AntonYudintsev commented 1 year ago

struct Foo
{
  Foo();
  ~Foo();
  Foo(const Foo& a);
};
vector<Foo> foo;
foo.resize(1);
foo.resize(200);//this line will call operator = on never constructed Foo, instead of copy constructor
In the end, operator = destructor will be called from never constructed elements.

this happens, because uninitialized_move_ptr uses is_trivially_copy_assignable (which is true), rather than is_trivially_copyable, I guess.
AntonYudintsev commented 1 year ago

It seems, that minimum possible fix is

--- a/prog/3rdPartyLibs/eastl/include/EASTL/memory.h
+++ b/prog/3rdPartyLibs/eastl/include/EASTL/memory.h
@@ -692,7 +692,7 @@ namespace eastl
        template <typename InputIterator, typename ForwardIterator>
        inline ForwardIterator uninitialized_move_impl(InputIterator first, InputIterator last, ForwardIterator dest, true_type)
        {
-           return eastl::copy(first, last, dest); // The copy() in turn will use memcpy for is_trivially_copy_assignable (e.g. POD) types.
+           return eastl::uninitialized_copy(first, last, dest); // The copy() in turn will use memcpy for is_trivially_copy_assignable (e.g. POD) types.
        }

        template <typename InputIterator, typename ForwardIterator>

which logically makes sense, since it should be uninitialized_copy. However, it will require is_trivial to perform, rather than is_trivially_copyable