Don't use the union trick to do unlawful casts

GCC 4.7 is printing this (bogus) warning:
qobject.h:166:15: warning: 'QObject::findChildren(const QString&, Qt::FindChildOptions) const [with T = QMenuBar*; Qt::FindChildOptions = QFlags<Qt::FindChildOption>]::<anonymous union>' declared with greater visibility than the type of its field 'QObject::findChildren(const QString&, Qt::FindChildOptions) const [with T = QMenuBar*; Qt::FindChildOptions = QFlags<Qt::FindChildOption>]::<anonymous union>::typedList' [-Wattributes]

Change-Id: I2d1c365e3191f3a5c7b2241deb35f0ae47d79afc
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2012-12-21 18:26:09 -08:00 committed by The Qt Project
parent 8a0a09f6d1
commit add16725a3

View File

@ -163,12 +163,8 @@ public:
inline QList<T> findChildren(const QString &aName = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
{
QList<T> list;
union {
QList<T> *typedList;
QList<void *> *voidList;
} u;
u.typedList = &list;
qt_qFindChildren_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
qt_qFindChildren_helper(this, aName, reinterpret_cast<T>(0)->staticMetaObject,
reinterpret_cast<QList<void *> *>(&list), options);
return list;
}
@ -177,12 +173,8 @@ public:
inline QList<T> findChildren(const QRegExp &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
{
QList<T> list;
union {
QList<T> *typedList;
QList<void *> *voidList;
} u;
u.typedList = &list;
qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject,
reinterpret_cast<QList<void *> *>(&list), options);
return list;
}
#endif
@ -192,12 +184,8 @@ public:
inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
{
QList<T> list;
union {
QList<T> *typedList;
QList<void *> *voidList;
} u;
u.typedList = &list;
qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject, u.voidList, options);
qt_qFindChildren_helper(this, re, reinterpret_cast<T>(0)->staticMetaObject,
reinterpret_cast<QList<void *> *>(&list), options);
return list;
}
#endif