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

QStringView::toWCharArray implicit conversion

    XMLWordPrintable

Details

    • All
    • c0c2efc3c62432b4ae159b911018682f573b54e4 (qt/qtbase/5.14)

    Description

      When compiling application against 5.14.1 I receive this warning on msvc compiler:

      'return': conversion from 'qsizetype' to 'int', possible loss of data	C:\Qt\5.14.1\msvc2017_64\include\QtCore/qstring.h	1125	
      

      The code in question:

      int QStringView::toWCharArray(wchar_t *array) const
      {
          if (sizeof(wchar_t) == sizeof(QChar)) {
              if (auto src = data())
                  memcpy(array, src, sizeof(QChar) * size());
              return size();
          } else {
              return QString::toUcs4_helper(reinterpret_cast<const ushort *>(data()), int(size()),
                                            reinterpret_cast<uint *>(array));
          }
      }
      

       

      return size();
      

      in this case size() returns a qsizetype, but toWCharArray is expects to return an int. I believe qsizetype is typedefd as size_t. Types therefore mismatch.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            watsontandrew Andrew Watson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes