Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66635

QSharedDataPointer detaches in unexpected situations

XMLWordPrintable

      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 ()

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            thiago Thiago Macieira
            jirauser26727 user-04d21 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes