On 5/15/19 2:36 PM, Will Godfrey wrote:
My understanding is that nullptr is the 'modern' replacement for NULL, so I
can't see why it would fail.

  It is.

In this case, the older version of QSharedPointer provides no way for the compiler to convert a nullptr (which is actually a nullptr_t) to a QSharedPointer which operator= requires. It's a bit convoluted and only happens in rare situations. QSharedPointer prior to Qt 5.8 is unfortunately one of those situations.

  Gorey details are attached in a small test program.

As a cross-check I tried changing a few old-style NULL with nullptr in
Yoshimi, and it compiled without complaint, so I'm quite lost now :(

  In most cases, nullptr is a drop-in replacement for NULL.

// nullptr.cpp

// To Build:
//     g++ -std=c++11 nullptr.cpp

// __cplusplus values:
//    201103L = C++11
//    199711L = C++98 (g++ 4.7 default)
#if __cplusplus >= 201103L
    // This is C++11!
    #error Need to build with -std=c++11

class A
    explicit A(int *p) { m_p = p; }

    // Ugh.  Avoid assignment operators if you can.
    A &operator=(const A &rhs)
        m_p = rhs.m_p;

    int *m_p;

int main()
    // nullptr is compatible with pointers in general.
    int *p = nullptr;

    // This is also OK.
    A a(nullptr);

    // This is not.  Because the ctor is explicit, we must 
    // explicitly ask for the conversion for this to work.
    //a = nullptr;

    // Explicitly asking for the conversion works.
    a = static_cast<A>(nullptr);

    // Adding a (non-explicit) ctor to A that takes a nullptr_t
    // also fixes the problem.  Qt 5.8 adds this to QSharedPointer.

    return 0;

Rosegarden-user mailing list
Rosegarden-user@lists.sourceforge.net - use the link below to unsubscribe

Reply via email to