diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 41fc07521d..d262d6a61b 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1124,7 +1124,8 @@ void QMetaStringTable::writeBlob(char *out) int size = str.size(); qptrdiff offset = offsetOfStringdataMember + stringdataOffset - i * sizeof(QByteArrayData); - const QByteArrayData data = { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset }; + const QByteArrayData data = + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset); memcpy(out + i * sizeof(QByteArrayData), &data, sizeof(QByteArrayData)); diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index be96d895a2..ad2cb02213 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -2215,11 +2215,11 @@ struct qt_meta_stringdata_QSignalEventGenerator_t { QByteArrayData data[3]; char stringdata[32]; }; -#define QT_MOC_LITERAL(idx, ofs, len) { \ - Q_REFCOUNT_INITIALIZE_STATIC, len, 0, 0, \ - offsetof(qt_meta_stringdata_QSignalEventGenerator_t, stringdata) + ofs \ +#define QT_MOC_LITERAL(idx, ofs, len) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ + offsetof(qt_meta_stringdata_QSignalEventGenerator_t, stringdata) + ofs \ - idx * sizeof(QByteArrayData) \ - } + ) static const qt_meta_stringdata_QSignalEventGenerator_t qt_meta_stringdata_QSignalEventGenerator = { { QT_MOC_LITERAL(0, 0, 21), diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 71244e0eab..5961d682c5 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -618,10 +618,8 @@ static inline char qToLower(char c) return c; } -const QStaticByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZE_STATIC, - 0, 0, 0, sizeof(QByteArrayData) }, { 0 } }; -const QStaticByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZE_STATIC, - 0, 0, 0, sizeof(QByteArrayData) }, { 0 } }; +const QStaticByteArrayData<1> QByteArray::shared_null = { Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(0), { 0 } }; +const QStaticByteArrayData<1> QByteArray::shared_empty = { Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(0), { 0 } }; /*! \class QByteArray diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 2065c8fe91..93e241904d 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -149,14 +149,22 @@ struct QByteArrayDataPtr QByteArrayData *ptr; }; +#define Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ + { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ + /**/ + +#define Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(size) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QByteArrayData)) \ + /**/ #if defined(Q_COMPILER_LAMBDA) # define QByteArrayLiteral(str) \ ([]() -> QByteArrayDataPtr { \ enum { Size = sizeof(str) - 1 }; \ - static const QStaticByteArrayData qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, sizeof(QByteArrayData) }, str }; \ + static const QStaticByteArrayData qbytearray_literal = { \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ + str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ return holder; \ }()) \ @@ -170,8 +178,9 @@ struct QByteArrayDataPtr # define QByteArrayLiteral(str) \ __extension__ ({ \ enum { Size = sizeof(str) - 1 }; \ - static const QStaticByteArrayData qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, sizeof(QByteArrayData) }, str }; \ + static const QStaticByteArrayData qbytearray_literal = { \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ + str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ holder; \ }) \ diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3bd2deee66..6935c76b42 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -796,8 +796,8 @@ const QString::Null QString::null = { }; \sa split() */ -const QStaticStringData<1> QString::shared_null = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, false, sizeof(QStringData) }, { 0 } }; -const QStaticStringData<1> QString::shared_empty = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, false, sizeof(QStringData) }, { 0 } }; +const QStaticStringData<1> QString::shared_null = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; +const QStaticStringData<1> QString::shared_empty = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; int QString::grow(int size) { diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 50796a9e29..202b74dfbf 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -117,8 +117,9 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, # define QStringLiteral(str) \ ([]() -> QStringDataPtr { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ - static const QStaticStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, sizeof(QStringData) }, QT_UNICODE_LITERAL(str) }; \ + static const QStaticStringData qstring_literal = { \ + Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ + QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ return holder; \ }()) \ @@ -132,8 +133,9 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, # define QStringLiteral(str) \ __extension__ ({ \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ - static const QStaticStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, sizeof(QStringData) }, QT_UNICODE_LITERAL(str) }; \ + static const QStaticStringData qstring_literal = { \ + Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ + QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ holder; \ }) \ @@ -149,6 +151,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, # define QStringLiteral(str) QLatin1String(str) #endif +#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ + { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ + /**/ + +#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER(size) \ + Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QStringData)) \ + /**/ + template struct QStaticStringData { diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp index cc2712297d..dda20cde04 100644 --- a/src/dbus/qdbusabstractadaptor.cpp +++ b/src/dbus/qdbusabstractadaptor.cpp @@ -327,11 +327,11 @@ struct qt_meta_stringdata_QDBusAdaptorConnector_t { QByteArrayData data[10]; char stringdata[96]; }; -#define QT_MOC_LITERAL(idx, ofs, len) { \ - Q_REFCOUNT_INITIALIZE_STATIC, len, 0, 0, \ +#define QT_MOC_LITERAL(idx, ofs, len) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ offsetof(qt_meta_stringdata_QDBusAdaptorConnector_t, stringdata) + ofs \ - idx * sizeof(QByteArrayData) \ - } + ) static const qt_meta_stringdata_QDBusAdaptorConnector_t qt_meta_stringdata_QDBusAdaptorConnector = { { QT_MOC_LITERAL(0, 0, 21), diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 71df7e7579..cc66ca9963 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -196,11 +196,11 @@ void Generator::generateCode() // stringdata.stringdata member, and 2) the stringdata.data index of the // QByteArrayData being defined. This calculation relies on the // QByteArrayData::data() implementation returning simply "this + offset". - fprintf(out, "#define QT_MOC_LITERAL(idx, ofs, len) { \\\n" - " Q_REFCOUNT_INITIALIZE_STATIC, len, 0, 0, \\\n" + fprintf(out, "#define QT_MOC_LITERAL(idx, ofs, len) \\\n" + " Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \\\n" " offsetof(qt_meta_stringdata_%s_t, stringdata) + ofs \\\n" " - idx * sizeof(QByteArrayData) \\\n" - " }\n", + " )\n", qualifiedClassNameIdentifier.constData()); fprintf(out, "static const qt_meta_stringdata_%s_t qt_meta_stringdata_%s = {\n", diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp index 429652d92d..862789cc73 100644 --- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -109,7 +109,7 @@ void runScenario() { static const QStaticStringData<12> literalData = { - { Q_REFCOUNT_INITIALIZE_STATIC, 12, 0, 0, sizeof(QStringData) }, + Q_STATIC_STRING_DATA_HEADER_INITIALIZER(12), { 's', 'o', 'm', 'e', ' ', 'l', 'i', 't', 'e', 'r', 'a', 'l' } }; static QStringDataPtr literal = { literalData.data_ptr() }; @@ -228,7 +228,7 @@ void runScenario() { static const QStaticByteArrayData<12> literalData = { - { Q_REFCOUNT_INITIALIZE_STATIC, 12, 0, 0, sizeof(QByteArrayData) }, + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(12), { 's', 'o', 'm', 'e', ' ', 'l', 'i', 't', 'e', 'r', 'a', 'l' } }; static QByteArrayDataPtr literal = { literalData.data_ptr() };