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

Const-correctness error in assignment operator of compute::vector #4323

Closed
PrimeF opened this issue Jan 23, 2020 · 2 comments
Closed

Const-correctness error in assignment operator of compute::vector #4323

PrimeF opened this issue Jan 23, 2020 · 2 comments

Comments

@PrimeF
Copy link
Contributor

PrimeF commented Jan 23, 2020

Expected Behavior

The compute vector assigns another compute vector.

Actual Behavior

A const-correctness error is thrown, when assigning a compute vector to another compute vector.

Steps to Reproduce the Problem

  1. Initialize two compute vectors
  2. Assign one to the other

Specifications

  • HPX Version: 1.4.0
  • Platform (compiler, OS): GCC 9.2.0, CentOS

Fix suggestions

As suggested by @K-ballo: vector::op= should be copying over other.alloc and operating with that instead

A quick fix working for me is:

vector& operator=(vector const& other)
        {
            if (this == &other)
                return *this;

            allocator_type tmpAlloc = other.alloc_;
            
            pointer data =
                alloc_traits::allocate(tmpAlloc, other.capacity_);
            hpx::parallel::util::copy(other.begin(), other.end(),
                iterator(data, 0, alloc_traits::target(tmpAlloc)));

            if (data_ != nullptr)
            {
                alloc_traits::bulk_destroy(alloc_, data_, size_);
                alloc_traits::deallocate(alloc_, data_, capacity_);
            }

            size_ = other.size_;
            capacity_ = other.capacity_;
            alloc_ = other.alloc_;
            data_ = std::move(data);

            return *this;
        }
@hkaiser
Copy link
Member

hkaiser commented Jan 23, 2020

@PrimeF Thanks for reporting! Would you mind creating a PR for this?

@PrimeF
Copy link
Contributor Author

PrimeF commented Jan 23, 2020

Sure, I will do one!

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

No branches or pull requests

2 participants