- 
    
Bug
 - 
    Resolution: Done
 - 
    
P3: Somewhat important
 - 
    5.10.0
 - 
    None
 
I found that QSharedDataPointer detaches in situation where it is unexpected.
For example:
QSharedDataPointer<foo> head; ... auto node = head; if (!node) // DO NOT cause detach() if (node == nullptr) // causes detach() if (node != nullptr) // causes detach() if (node) // causes detach()
Unless there is a good reason, I think this should not happen.
This can easily be solved eg. with stuff like:
template <class T> bool operator==(const QSharedDataPointer<T>& p, nullptr_t) { return p.constData() == nullptr; } template <class T> bool operator==(nullptr_t, const QSharedDataPointer<T>& p) { return p.constData() == nullptr; } template <class T> bool operator!=(nullptr_t, const QSharedDataPointer<T>& p) { return !!p; } template <class T> bool operator!=(const QSharedDataPointer<T>& p, nullptr_t) { return !!p; }
And by adding a bool operator.
On another hand, curiously, QExplicitlySharedDataPointer has an operator bool ()
- replaces
 - 
                    
QTBUG-66946 QSharedDataPointer detaches on ptrInst == nullptr
-         
 - Closed
 
 -         
 
| For Gerrit Dashboard: QTBUG-66635 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V | 
| 222680,2 | Add nullptr comparison to Q{Explicitly,}SharedDataPointer | dev | qt/qtbase | Status: MERGED | +2 | 0 |