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

QList::insert'ing indices out of order warns index is out of range

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.1
    • None
    • Linux/X11

    Description

      This code makes Qt log a warning:

      QList<int> test;
      test.insert(1, 0);
      test.insert(0, 0);
      

      The warning is:

      QList::insert(): Index out of range
      

      Using QList::reserve does not make a difference, even if the reserved size is orders of magnitude more than necessary. This still results in the warning:

      QList<int> test;
      test.reserve(2);
      test.insert(1, 0);
      test.insert(0, 0);
      

      This does not warn:

      QList<int> test;
      test.insert(0, 0);
      test.insert(1, 0);
      

      This is a regression from Qt 5.14. I presume it is somehow related to the upcoming changes to memory management in QList in Qt6, but if so I would have expected using QList::reserve to resolve the warning.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            be Be Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes