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

Mutz, Marc marc at kdab.com
Sat May 25 11:30:08 CEST 2019


Further to the question about default ctors for such "obvious" stuff as

On 2019-05-21 10:27, Mutz, Marc via Development wrote:
>     class QRect {
>        int x, y, w, h;
>     public:
>        QRect() = default;
>     };
>     QRect r; // partially-formed
>     r.x();   // compilers _already_ warn about this
>     QRect r = {}; // zero-initialized

I've been working with Qt for two decades now. Guess what I just wrote 
and had to debug?

    QSize zero;

Anyone spot the bug? Hint: the following /is/ correct:

    QPoint origin;

Now, anyone here who wants to defend that as good API design?

Anyone?

Repeat after me: default ctors do _not_ establish a valid value.

Thanks,
Marc


More information about the Development mailing list