diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 20f3ca9351..aa6a1e853c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -373,23 +373,6 @@ namespace QT_NAMESPACE {} Should be sorted most to least authoritative. */ -#if defined(__ghs) -# define Q_OUTOFLINE_TEMPLATE inline - -/* the following are necessary because the GHS C++ name mangling relies on __*/ -# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \ - static const int AFUNC ## _init_variable_ = AFUNC(); -# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC) -# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \ - class AFUNC ## _dest_class_ { \ - public: \ - inline AFUNC ## _dest_class_() { } \ - inline ~ AFUNC ## _dest_class_() { AFUNC(); } \ - } AFUNC ## _dest_instance_; -# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC) - -#endif - /* Symantec C++ is now Digital Mars */ #if defined(__DMC__) || defined(__SC__) # define Q_CC_SYM @@ -827,17 +810,23 @@ namespace QT_NAMESPACE {} #ifndef Q_CONSTRUCTOR_FUNCTION # define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \ - static const int AFUNC ## __init_variable__ = AFUNC(); + namespace { \ + static const struct AFUNC ## _ctor_class_ { \ + inline AFUNC ## _ctor_class_() { AFUNC(); } \ + } AFUNC ## _ctor_instance_; \ + } + # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC) #endif #ifndef Q_DESTRUCTOR_FUNCTION # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \ - class AFUNC ## __dest_class__ { \ - public: \ - inline AFUNC ## __dest_class__() { } \ - inline ~ AFUNC ## __dest_class__() { AFUNC(); } \ - } AFUNC ## __dest_instance__; + namespace { \ + static const struct AFUNC ## _dtor_class_ { \ + inline AFUNC ## _dtor_class_() { } \ + inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \ + } AFUNC ## _dtor_instance_; \ + } # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC) #endif diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index e0826595a3..02458a07e0 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -371,8 +371,8 @@ class Q_CORE_EXPORT QVariant protected: friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *); - friend int qRegisterGuiVariant(); - friend int qUnregisterGuiVariant(); + friend void qRegisterGuiVariant(); + friend void qUnregisterGuiVariant(); friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); #ifndef QT_NO_DEBUG_STREAM friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 859295de2b..da981b577b 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -126,8 +126,8 @@ QWindow *QGuiApplicationPrivate::focus_window = 0; Q_GLOBAL_STATIC(QMutex, applicationFontMutex) QFont *QGuiApplicationPrivate::app_font = 0; -extern int qRegisterGuiVariant(); -extern int qUnregisterGuiVariant(); +extern void qRegisterGuiVariant(); +extern void qUnregisterGuiVariant(); extern void qInitDrawhelperAsm(); extern void qInitImageConversions(); diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 9198e7f119..3b60f29e83 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -486,20 +486,18 @@ static const QMetaTypeInterface qVariantGuiHelper[] = { #undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES static const QVariant::Handler *qt_guivariant_last_handler = 0; -int qRegisterGuiVariant() +void qRegisterGuiVariant() { qt_guivariant_last_handler = QVariant::handler; QVariant::handler = &qt_gui_variant_handler; qMetaTypeGuiHelper = qVariantGuiHelper; - return 1; } Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) -int qUnregisterGuiVariant() +void qUnregisterGuiVariant() { QVariant::handler = qt_guivariant_last_handler; qMetaTypeGuiHelper = 0; - return 1; } Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant) diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp index ecc0280de2..f9e8432a8c 100644 --- a/src/gui/painting/qpaintbuffer.cpp +++ b/src/gui/painting/qpaintbuffer.cpp @@ -2166,14 +2166,12 @@ QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntryV2 &entry) return stream >> entry.bits; } -static int qRegisterPaintBufferMetaTypes() +static void qRegisterPaintBufferMetaTypes() { qRegisterMetaType(); qRegisterMetaTypeStreamOperators("QPaintBufferCacheEntry"); qRegisterMetaType(); qRegisterMetaTypeStreamOperators("QPaintBufferCacheEntryV2"); - - return 0; // something } Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes) diff --git a/src/widgets/animation/qguivariantanimation.cpp b/src/widgets/animation/qguivariantanimation.cpp index b0b18ed21b..f99b74e2ab 100644 --- a/src/widgets/animation/qguivariantanimation.cpp +++ b/src/widgets/animation/qguivariantanimation.cpp @@ -64,18 +64,17 @@ template<> Q_INLINE_TEMPLATE QQuaternion _q_interpolate(const QQuaternion &f,con return QQuaternion::slerp(f, t, progress); } -static int qRegisterGuiGetInterpolator() +static void qRegisterGuiGetInterpolator() { qRegisterAnimationInterpolator(_q_interpolateVariant); qRegisterAnimationInterpolator(_q_interpolateVariant); qRegisterAnimationInterpolator(_q_interpolateVariant); qRegisterAnimationInterpolator(_q_interpolateVariant); qRegisterAnimationInterpolator(_q_interpolateVariant); - return 1; } Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) -static int qUnregisterGuiGetInterpolator() +static void qUnregisterGuiGetInterpolator() { // casts required by Sun CC 5.5 qRegisterAnimationInterpolator( @@ -88,8 +87,6 @@ static int qUnregisterGuiGetInterpolator() (QVariant (*)(const QVector4D &, const QVector4D &, qreal))0); qRegisterAnimationInterpolator( (QVariant (*)(const QQuaternion &, const QQuaternion &, qreal))0); - - return 1; } Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index beeb3dad17..472f19a3c1 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -859,8 +859,8 @@ QApplication::QApplication(Display *dpy, int &argc, char **argv, #endif // Q_WS_X11 #ifndef QT_NO_STATEMACHINE -extern int qRegisterGuiStateMachine(); -extern int qUnregisterGuiStateMachine(); +void qRegisterGuiStateMachine(); +void qUnregisterGuiStateMachine(); #endif /*! diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index 2e945d28e1..18fec508ea 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -151,19 +151,17 @@ static const QMetaTypeInterface qVariantWidgetsHelper[] = { extern Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler; -int qRegisterWidgetsVariant() +void qRegisterWidgetsVariant() { qt_widgets_variant_handler = &widgets_handler; qMetaTypeWidgetsHelper = qVariantWidgetsHelper; - return 1; } Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant) -int qUnregisterWidgetsVariant() +void qUnregisterWidgetsVariant() { qt_widgets_variant_handler = 0; qMetaTypeWidgetsHelper = 0; - return 1; } Q_DESTRUCTOR_FUNCTION(qUnregisterWidgetsVariant) diff --git a/src/widgets/statemachine/qguistatemachine.cpp b/src/widgets/statemachine/qguistatemachine.cpp index 7a498eb77f..f717662ace 100644 --- a/src/widgets/statemachine/qguistatemachine.cpp +++ b/src/widgets/statemachine/qguistatemachine.cpp @@ -474,18 +474,16 @@ const QStateMachinePrivate::Handler qt_gui_statemachine_handler = { }; static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = 0; -int qRegisterGuiStateMachine() +void qRegisterGuiStateMachine() { qt_guistatemachine_last_handler = QStateMachinePrivate::handler; QStateMachinePrivate::handler = &qt_gui_statemachine_handler; - return 1; } Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine) -int qUnregisterGuiStateMachine() +void qUnregisterGuiStateMachine() { QStateMachinePrivate::handler = qt_guistatemachine_last_handler; - return 1; } Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index b3115e036e..23ec228c68 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -53,6 +53,7 @@ private slots: void qtry(); void checkptr(); void qstaticassert(); + void qConstructorFunction(); }; void tst_QGlobal::qIsNull() @@ -353,5 +354,17 @@ void tst_QGlobal::qstaticassert() QVERIFY(true); // if the test compiles it has passed. } +static int qConstructorFunctionValue; +static void qConstructorFunctionCtor() +{ + qConstructorFunctionValue = 123; +} +Q_CONSTRUCTOR_FUNCTION(qConstructorFunctionCtor); + +void tst_QGlobal::qConstructorFunction() +{ + QCOMPARE(qConstructorFunctionValue, 123); +} + QTEST_MAIN(tst_QGlobal) #include "tst_qglobal.moc"