Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AntonYudintsev opened this issue Sep 7, 2022 · 1 comment

Comments

@AntonYudintsev
Copy link
Contributor

AntonYudintsev commented Sep 7, 2022

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
Copy link
Contributor Author

AntonYudintsev commented Sep 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant