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

Wrapping a QKeyValueIterator in a std::reverse_iterator leads to undefined behavior

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14
    • None

    Description

      QKeyValueIterator<K&,V&> defines some STL-compatibility nested typedefs:

      using value_type = std::pair<K&,V&>;
      using reference = const value_type &;

      QKeyValueIterator::operator* return type is value_type.

      std::reverse_iterator::operator* return type is reference.

      Therefore, if a QKeyValueIterator is wrapped in a reverse_iterator, then reverse_iterator::operator* will return a dangling reference to the temporary object returned by QKeyValueIterator::operator*.

      A possible solution would be to change the definition of reference:

      using reference = value_type;

      This would be consistent with the STL principle that the reference typedef doesn't actually need to be a reference type, if it is a proxy type that can behave like a reference.

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            oktalist Mat Sutcliffe
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes