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

Self-move-assign of array nullifies the storage while keeping the shape the same #11

Open
Wentzell opened this issue Feb 16, 2021 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@Wentzell
Copy link
Member

Wentzell commented Feb 16, 2021

This is to keep track of an open discussion as to how we want to handle self-move-assignment for basic_array.

basic_array<double, 1> A(3);
A() = 9;
A = std::move(A);

This calls the defaulted move-assignment

basic_array &operator=(basic_array &&x) = default;

which will trigger a stack-copy of the shape (idx_map), while nullifying the storage (handle). C.f.

    handle_heap &operator=(handle_heap &&x) noexcept {
      if (not sptr and not(is_null())) destruct({_data, _size});
      _data   = x._data;
      _size   = x._size;
      sptr    = std::move(x.sptr);
      x._data = nullptr;
      x._size = 0;
      return *this;
    }

In other words the array ends up with null-storage and non-zero shape.
Do we want to protect the handle move-assign for this == &x ?

C.f. also https://ericniebler.com/2017/03/31/post-conditions-on-self-move/

@Wentzell Wentzell added the question Further information is requested label Feb 16, 2021
@Wentzell Wentzell changed the title Self-move-assign of array nullifies the storage while keeping the shape the same Self-move-assign of array nullifies the storage while keeping the layout the same Feb 16, 2021
@Wentzell Wentzell changed the title Self-move-assign of array nullifies the storage while keeping the layout the same Self-move-assign of array nullifies the storage while keeping the shape the same Feb 16, 2021
@parcollet
Copy link
Member

It indeed leaves the array "in a valid but unspecified state"..., in fact in a simple state...
We don't have to protect it I think.
But we could add an assert in handle_heap this !=x in debug mode (NDA_DEBuG) ?

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

No branches or pull requests

2 participants