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

QString can be compared with NULL if (and only if) QT_NO_CAST_TO_ASCII/QT_NO_CAST_FROM_ASCII is set

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P2: Important
    • 5.0.0
    • 4.4.1
    • None

    Description

      As reproducible with the following example, which should not compile. It does not compile when QT_NO_CAST_FROM_ASCII/QT_NO_CAST_TO_ASCII are not set.

      #define QT_NO_CAST_FROM_ASCII
      #define QT_NO_CAST_TO_ASCII
      
      #include <QtCore/QString>
      
      
      int main(int argc, char* argv[])
      {
          QString q;
          bool b = q == NULL;
          return 0;
      }
      

      NULL gets implicitly converted into a QStringRef, which then executes the following comparison operator:

      bool operator==(const QString &s1,const QStringRef &s2)

      It might be possible to fix this by making the following c'tor explicit:

      inline QStringRef::QStringRef(const QString *aString)
          :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){}
      

      Attachments

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

        Activity

          People

            stormols Marius Storm-Olsen
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes