From 6f4212e5936b96a8be0eacddbfc4dd7ca5abd776 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 2 Aug 2011 15:58:48 +0200 Subject: Fix QString/QByteArray literals for MSVC2010 (compilation of tests). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Specify return type of QByteArrayLiteral/QStringLiteral lambdas. - Define QT_UNICODE_LITERAL instead of QT_UNICODE_MARKER. Change-Id: I8a53506887d2736b093798220b088f645f05e415 Reviewed-on: http://codereview.qt.nokia.com/2514 Reviewed-by: Qt Sanity Bot Reviewed-by: João Abecasis --- src/corelib/tools/qbytearray.h | 2 +- src/corelib/tools/qstring.h | 23 +++++++++++++++-------- tests/auto/qstring/tst_qstring.cpp | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 5cf4c15179..b70dba4d55 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -146,7 +146,7 @@ template struct QConstByteArrayDataPtr #if defined(Q_COMPILER_LAMBDA) -# define QByteArrayLiteral(str) ([]() { \ +# define QByteArrayLiteral(str) ([]() -> QConstByteArrayDataPtr { \ enum { Size = sizeof(str) - 1 }; \ static const QConstByteArrayData qbytearray_literal = \ { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \ diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 4471da4b09..209994de16 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -102,7 +102,8 @@ template struct QConstStringData const QStringData str; const char16_t data[N + 1]; }; -#define QT_QSTRING_UNICODE_MARKER u"" + +#define QT_UNICODE_LITERAL_II(str) u"" str #elif defined(Q_OS_WIN) || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) || defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536) // wchar_t is 2 bytes @@ -111,7 +112,12 @@ template struct QConstStringData const QStringData str; const wchar_t data[N + 1]; }; -#define QT_QSTRING_UNICODE_MARKER L"" + +#if defined(Q_CC_MSVC) +# define QT_UNICODE_LITERAL_II(str) L##str +#else +# define QT_UNICODE_LITERAL_II(str) L"" str +#endif #else template struct QConstStringData @@ -121,12 +127,13 @@ template struct QConstStringData }; #endif -#if defined(QT_QSTRING_UNICODE_MARKER) +#if defined(QT_UNICODE_LITERAL_II) +# define QT_UNICODE_LITERAL(str) QT_UNICODE_LITERAL_II(str) # if defined(Q_COMPILER_LAMBDA) -# define QStringLiteral(str) ([]() { \ - enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 - 1 }; \ +# define QStringLiteral(str) ([]() -> QConstStringDataPtr { \ + enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QConstStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \ + { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ QConstStringDataPtr holder = { &qstring_literal }; \ return holder; }()) @@ -137,9 +144,9 @@ template struct QConstStringData # define QStringLiteral(str) \ __extension__ ({ \ - enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 - 1 }; \ + enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QConstStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \ + { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ QConstStringDataPtr holder = { &qstring_literal }; \ holder; }) # endif diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp index 8c725fa109..f7a725c164 100644 --- a/tests/auto/qstring/tst_qstring.cpp +++ b/tests/auto/qstring/tst_qstring.cpp @@ -5110,7 +5110,7 @@ void tst_QString::toUpperLower_icu() void tst_QString::literals() { -#if defined(QT_QSTRING_UNICODE_MARKER) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) +#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) QString str(QStringLiteral("abcd")); QVERIFY(str.length() == 4); -- cgit v1.2.3