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

QString/QByteArray::isDetached() returns false for null strings

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Not Evaluated Not Evaluated
    • None
    • dev
    • None
    • All

      Currently QString/QByteArray::isDetached() returns false for null strings, and in some cases for empty strings, IIUC that's because it's implemented as:

      bool QString::isDetached() { return !d.isShared(); } // d is DataPointer
      bool QArrayDataPointer::isShared() { return !d || d->isShared(); }
      

      Logically a null string is detached/not-shared because it has no data array to begin with.

      Changing QDP::isShared() to return false when there is no d pointer

       return d && d->isShared() 

      could solve the issue.

      (And while at it, we could add a new method:

      QString/QByteArray::isShared() { return d.isShared(); }
      

      , the double negative "string is detached when its DataPointer is not shared " is harder to reason about than "string is shared when its DataPointer is shared").

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

            thiago Thiago Macieira
            ahmad.samir Ahmad Samir
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes