[Development] What's the status of a moved-from object?
Allan Sandfeld Jensen
kde at carewolf.com
Tue May 21 00:10:52 CEST 2019
On Montag, 20. Mai 2019 22:58:49 CEST Konstantin Shegunov wrote:
> 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?
If you are using Linux, they typically has debug-packages, and some crash
handlers (I know at least DrKonqi does), can suggest installing them and
reloading the backgrace producing even better bugreporting information than
you began with (even the basic ones would still tell you it is a nullptr
access and in which function). I don't see how we could improve on that. A log
entry or graceful error handling or exit would be more likely to missed by
Q_ASSERT is for developers, it is has nothing to do with end-users. Though
actually now that I think about it, a developer would get just as good details
from a nullptr segfault with full debug info, as from a Q_ASSERT, so it might
not even be needed.
More information about the Development