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

Problems with new qt5.5 QFlag helpers for qDebug

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.5.1
    • 5.5.0
    • Core: Other
    • None
    • Archlinux using gcc 5.1.0
    • Ibd260de88c174c1aa3833a56b153b8b74d337338

    Description

      ogoffart

      Since qt5.5 the following code will no longer compile:

      #include <QDebug>  //Needed to cause the error!
      #include <QDataStream>
      
      class TestClass {
      public:
          int a;
          QString b;
         //QDataStream operators ommited, for readability
      };
      
      template QDataStream& operator<< <TestClass>(QDataStream&, QList<TestClass> const&);
      template QDataStream& operator>> <TestClass>(QDataStream&, QList<TestClass>&);
      
      

      Error:

      /usr/include/qt/QtCore/qflags.h:88: error: invalid application of 'sizeof' to incomplete type 'QStaticAssertFailure<false>'
      Q_STATIC_ASSERT_X((sizeof(Enum) <= sizeof(int)),
      ^
      /usr/include/qt/QtCore/qtypetraits.h:-1: In instantiation of 'struct QtPrivate::is_unsigned<TestClass>':
      /usr/include/qt/QtCore/qflags.h:103: required from 'class QFlags<TestClass>'
      /usr/include/qt/QtCore/qmetatype.h:1386: required from 'struct QtPrivate::IsQEnumHelper<QFlags<TestClass> >'
      /usr/include/qt/QtCore/qdebug.h:290: required by substitution of 'template<class T> typename QtPrivate::QEnableIf<((! QtPrivate::IsQEnumHelper<T>::Value) && (! QtPrivate::IsQEnumHelper<QFlags<T> >::Value)), QDebug>::Type operator<<(QDebug, const QFlags<T>&) [with T = TestClass]'

      The reason for this is a unsafe template in qdebug.h:290

      I suggest adding a safe QtPrivate::IsQFlagsHelper<T> instead of using QtPrivate::IsQEnumHelper<QFlags<T> >.

      That new IsQFlagsHelper would first have to check if T is an integral type, before instantiating QFlags<T>.

      Attachments

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

        Activity

          People

            ogoffart Olivier Goffart (Woboq GmbH)
            dreamcooled Mr Dreamcooled
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes