- 
    Bug 
- 
    Resolution: Done
- 
    P3: Somewhat important 
- 
    5.15.0
- 
    None
- 
        95afe6b244dbd9623a92399d1bed0b9f52aa1e65 (qt/qtbase/dev) 73d6c2058fcb23ec9d126b7f862cf588d31222af (qt/qtbase/5.15)
QSharedPointer does not call the custom deleter when the pointer is a nullptr. This differs from std::shared_ptr<>, which will call the deleter in this case.
The documentation suggests that it will be called: https://doc.qt.io/qt-5/qsharedpointer.html#QSharedPointer-4
Creates a QSharedPointer that is null. This is equivalent to the QSharedPointer default constructor. The deleter parameter d specifies the custom deleter for this object. The custom deleter is called, instead of the operator delete(), when the strong reference count drops to 0.
Example code:
#include <iostream> #include <memory>#include <QtCore/QSharedPointer>int main() { std::shared_ptr<int>(nullptr, [](int *i) { std::cout << "deleter std::shared_ptr" << std::endl; }); QSharedPointer<int>(nullptr, [](int *i) { std::cout << "deleter QSharedPointer" << std::endl; }); }
This will print:
deleter std::shared_ptr
Either the behavior should be changed to call the deleter even for nullptrs or the documentation should be updated to indicate that for nullptrs no deleter will be called.