[Development] What's the status of a moved-from object?

Konstantin Shegunov kshegunov at gmail.com
Mon May 20 22:58:49 CEST 2019

On Mon, May 20, 2019 at 10:07 PM Allan Sandfeld Jensen <kde at carewolf.com>

> On Montag, 20. Mai 2019 20:18:32 CEST Mutz, Marc via Development wrote:
> > Where we still, maybe, disagree, is whether d == nullptr is a valid
> > state. The difference is whether member functions other then destruction
> > and assignment check for a nullptr d. I'd propose that on classes under
> > the above premiss, Q_D contains Q_ASSERT(d). This, I think, strikes the
> > best balance between safety and speed.
> I agree. I would consider anything other than deleting or reassigning  a
> moved
> object undefined behavior, so asserting on it seems like a good help to
> users
> of our APIs.

I agree as well, although I have a minor nitpick. Q_ASSERT works only if it
was not stripped while building Qt. Meaning that I'm often working, as I'm
sure other users, on Linux especially, with the default (i.e. release)
version of Qt from the repo. Granted it may be my own fault, but in this
case the assert isn't tripped and this code simply segfaults for reasons
that aren't so obvious. Any suggestions how to mitigate that? Somehow
*suggest* to the user that [s]he's supposed to build in debug mode
otherwise they're on their own?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190520/bdd4d55e/attachment.html>

More information about the Development mailing list