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

qiterator.h forward declares iterator categories

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 4.8.2, 5.0.0 Beta 1
    • 4.8.0, 4.8.1, 5.0.0 Beta 1
    • None
    • Linux with libc++, Mac OS X with libc++.
    • 19e2b4d6eb733d9fd4eb69c0622b699fd08a3203 5210d47aa66214e3cb16f394d0510a91f770c1b1

    Description

      qiterator.h has the following piece of code:

      namespace std {
          struct bidirectional_iterator_tag;
          struct random_access_iterator_tag;
      }
      

      This breaks compilation with libc++ because libc++ has these in std::__1 (currently, might change in future as its version is bumped). Forward declaring things in std namespace is forbidden by the standard, so that piece of code should not have been written. It should be replaced by #include <iterator>.

      Here is a minimal example that is broken by this bug:

      #include <iterator>
      #include <QObject>
      
      class A {};
      
      template<typename T>
      class X
      {
      public:
          class iterator {
          public:
              typedef std::random_access_iterator_tag  iterator_category;
              typedef ptrdiff_t difference_type;
              typedef T value_type;
              typedef T *pointer;
              typedef T &reference;
          };  
          
      };
      
      void t()
      {
        std::iterator_traits<X<A*>::iterator>::iterator_category x;
      }
      

      test.cc:23:42: error: no member named 'iterator_category' in 'std::__1::iterator_traits<X<A *>::iterator>'
      std::iterator_traits<X<A*>::iterator>::iterator_category x;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      1 error generated.

      This is probably the root cause of QTBUG-25922.

      Attachments

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

        Activity

          People

            bhughes Bradley T. Hughes (closed Nokia Identity) (Inactive)
            gribozavr Dmitri Gribenko
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes