[Development] Move ctors for q_declare_shared types

Daniel Teske Daniel.Teske at theqtcompany.com
Fri Jun 26 12:34:31 CEST 2015


> Most of our implicitly shared types already had a move-assignment operator,
> because it's just
> 
>    QFoo &operator=(QForr &&other) { swap(other); return *this; }
And that's indeed how QVector's move assignment is implemented.

It's also broken.

Just because other is a rvalue reference does not mean that it is a temporary 
and thus the is no guarantee that other's dtor gets called.

And thus, this line:

QVector<Klass> vector = std::move(something);

does not gurantees that the dtors for the old contents of vector are called. 

For standard containers, this is specified in *container.requirements*
To quote, with: a being a container and rv a non-const rvalue of the same 
type:

a = rv

"All existing elements of a are either move assigned to or destroyed,"

I do not see any reason why our containers should not give the same guarantee 
for move assignment and consider this a bug.

daniel



More information about the Development mailing list