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

CC compiler shows a warning when compiling qobject.h

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 4.8.0
    • 4.7.1
    • Core: Object Model
    • None
    • Solaris
    • 5e3c4b6a82df640c15778af72384c6b27f8860b7

    Description

      The current implementation of qobject_cast qobject.h makes the CC compiler raise severe warnings:
      Warning, nullref: Initializing const myClass& to a NULL value.

      This is because of the 1rst statement reinterpret_cast<T>(0) wich is used to call the not static method qt_check_for_QOBJECT_macro:
      template <class T>
      inline T qobject_cast(QObject *object)
      {
      #if !defined(QT_NO_MEMBER_TEMPLATES) && !defined(QT_NO_QOBJECT_CHECK)
      reinterpret_cast<T>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(object));
      #endif
      return static_cast<T>(reinterpret_cast<T>(0)->staticMetaObject.cast(object));
      }

      The quick and temporary solution is to setup the variable QT_NO_QOBJECT_CHECK, but the longer term one might probably to have:
      template <class T>
      inline T qobject_cast(QObject *object)
      {
      #if !defined(QT_NO_MEMBER_TEMPLATES) && !defined(QT_NO_QOBJECT_CHECK)
      reinterpret_cast<T>( object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(object));
      #endif
      return static_cast<T>(reinterpret_cast<T>( object)->staticMetaObject.cast(object));
      }

      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)
            mpejcoch Martin Pejcoch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes