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

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

    XMLWordPrintable

Details

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

    Description

      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").

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes