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

comparing QList begin() and constBegin() gives invalid result on first run

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.7.2, 4.8.0
    • None
    • MSVC 2010 (Qt 4.8) and MSVC 2008 (Qt 4.7.2)

    Description

      --snip--
      QList<int> test;
      if (test.begin() == test.constBegin())
      doSomething();
      if (test.begin() == test.constBegin())
      doSomethingElse();
      --snip--

      Only doSomethingElse() will be executed. If comparisons are written by settings constBegin() first and begin() last, then both are executed.

      AFAIK this happens because list has internal reference count of zero and therefore begin() runs detach() on first run and test.constBegin() is executed first.

      I don't know if this should be fixed or just documented to API, but currently it works bit dangerously (even though users should not mix constBegin() and begin(), or constBegin() and end()).

      I understand API like this comparison should be valid in all cases no matter how smart it is since iterator has operator==(const const_iterator& other) const.

      Attachments

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

        Activity

          People

            earthdomain Earth Domain (Inactive)
            timit Timi Tuohenmaa
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes