qt5-qtbase/0221-QObject-fix-GCC-6-warning-about-qt_static_metacall-s.patch

150 lines
4.8 KiB
Diff
Raw Normal View History

From 2020d2cb63b851723e188c002acbe25b5f066525 Mon Sep 17 00:00:00 2001
From: Marc Mutz <marc.mutz@kdab.com>
Date: Fri, 4 Mar 2016 15:19:50 -0800
Subject: [PATCH 221/328] QObject: fix GCC 6 warning about qt_static_metacall's
'hidden' attribute use
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This warning is triggered when we try to apply the Q_DECL_HIDDEN
attribute to a class in an unnamed namespace. Such classes are
already not exported.
qobjectdefs.h:175:108: warning: visibility attribute ignored [-Wattributes]
qobjectdefs.h:198:108: warning: visibility attribute ignored [-Wattributes]
Added a test on gadgets (and QObjects) in unnamed namespaces,
because qtbase currently does not contain such Q_GADGETs.
Done-with: Thiago Macieira <thiago.macieira@intel.com>
Change-Id: Ic747cc2ab45e4dc6bb70ffff1438c747b05c5672
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
---
src/corelib/kernel/qobjectdefs.h | 15 ++++++++++--
tests/auto/tools/moc/tst_moc.cpp | 50 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index b1ed971..2e9ed4f 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -152,6 +152,12 @@ inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
# define Q_OBJECT_NO_OVERRIDE_WARNING
#endif
+#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 600
+# define Q_OBJECT_NO_ATTRIBUTES_WARNING QT_WARNING_DISABLE_GCC("-Wattributes")
+#else
+# define Q_OBJECT_NO_ATTRIBUTES_WARNING
+#endif
+
/* qmake ignore Q_OBJECT */
#define Q_OBJECT \
public: \
@@ -162,10 +168,11 @@ public: \
virtual const QMetaObject *metaObject() const; \
virtual void *qt_metacast(const char *); \
virtual int qt_metacall(QMetaObject::Call, int, void **); \
- QT_WARNING_POP \
QT_TR_FUNCTIONS \
private: \
+ Q_OBJECT_NO_ATTRIBUTES_WARNING \
Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
+ QT_WARNING_POP \
struct QPrivateSignal {};
/* qmake ignore Q_OBJECT */
@@ -179,7 +186,11 @@ public: \
void qt_check_for_QGADGET_macro(); \
typedef void QtGadgetHelper; \
private: \
- Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
+ QT_WARNING_PUSH \
+ Q_OBJECT_NO_ATTRIBUTES_WARNING \
+ Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
+ QT_WARNING_POP \
+ /*end*/
#endif // QT_NO_META_MACROS
#else // Q_MOC_RUN
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index c113b7c..5c16c7a 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -131,6 +131,33 @@ typedef struct {
int doNotConfuseMoc;
} OldStyleCStruct;
+namespace {
+
+ class GadgetInUnnamedNS
+ {
+ Q_GADGET
+ Q_PROPERTY(int x READ x WRITE setX)
+ Q_PROPERTY(int y READ y WRITE setY)
+ public:
+ explicit GadgetInUnnamedNS(int x, int y) : m_x(x), m_y(y) {}
+ int x() const { return m_x; }
+ int y() const { return m_y; }
+ void setX(int x) { m_x = x; }
+ void setY(int y) { m_y = y; }
+
+ private:
+ int m_x, m_y;
+ };
+
+ class ObjectInUnnamedNS : public QObject
+ {
+ Q_OBJECT
+ public:
+ explicit ObjectInUnnamedNS(QObject *parent = Q_NULLPTR) : QObject(parent) {}
+ };
+
+}
+
class Sender : public QObject
{
Q_OBJECT
@@ -597,6 +624,7 @@ private slots:
void relatedMetaObjectsNameConflict_data();
void relatedMetaObjectsNameConflict();
void strignLiteralsInMacroExtension();
+ void unnamedNamespaceObjectsAndGadgets();
void veryLongStringData();
void gadgetHierarchy();
@@ -3421,6 +3449,28 @@ class VeryLongStringData : public QObject
#undef repeat65534
};
+void tst_Moc::unnamedNamespaceObjectsAndGadgets()
+{
+ // these just test very basic functionality of gadgets and objects
+ // defined in unnamed namespaces.
+ {
+ GadgetInUnnamedNS gadget(21, 42);
+ QCOMPARE(gadget.x(), 21);
+ QCOMPARE(gadget.y(), 42);
+ gadget.staticMetaObject.property(0).writeOnGadget(&gadget, 12);
+ gadget.staticMetaObject.property(1).writeOnGadget(&gadget, 24);
+ QCOMPARE(gadget.x(), 12);
+ QCOMPARE(gadget.y(), 24);
+ }
+
+ {
+ ObjectInUnnamedNS object;
+ QObject *qObject = &object;
+ QCOMPARE(static_cast<ObjectInUnnamedNS *>(qObject),
+ qobject_cast<ObjectInUnnamedNS *>(qObject));
+ }
+}
+
void tst_Moc::veryLongStringData()
{
const QMetaObject *mobj = &VeryLongStringData::staticMetaObject;
--
1.9.3