summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.h
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-02-17 20:10:34 +0100
committerLiang Qi <liang.qi@qt.io>2017-02-17 20:10:34 +0100
commitbc4cd465dd5df82e13f3c7709166ee11289d219f (patch)
treed6323aaed6383e589fbefb6057648c22bb187c76 /src/corelib/tools/qstring.h
parent43daefb0962794b2df256cae1098e889b9b36f12 (diff)
parent07745d7bfbf6c8d83e0243150d8ce934675dea87 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: qmake/Makefile.unix Change-Id: Ia18e391198222eef34ffa2df6f683e052058d032
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r--src/corelib/tools/qstring.h45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 87d9c07a8b..36edcc7242 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -147,15 +147,10 @@ typedef QLatin1String QLatin1Literal;
typedef QTypedArrayData<ushort> QStringData;
-#if defined(Q_COMPILER_UNICODE_STRINGS)
-
-#define QT_UNICODE_LITERAL_II(str) u"" str
-typedef char16_t qunicodechar;
-
-#elif defined(Q_OS_WIN) \
- || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) \
- || (!defined(__SIZEOF_WCHAR_T__) && defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536))
-// wchar_t is 2 bytes
+#if defined(Q_OS_WIN) && !defined(Q_COMPILER_UNICODE_STRINGS)
+// fall back to wchar_t if the a Windows compiler does not
+// support Unicode string literals, assuming wchar_t is 2 bytes
+// on that platform (sanity-checked by static_assert further below)
#if defined(Q_CC_MSVC)
# define QT_UNICODE_LITERAL_II(str) L##str
@@ -165,21 +160,22 @@ typedef char16_t qunicodechar;
typedef wchar_t qunicodechar;
#else
+// all our supported compilers support Unicode string literals,
+// even if their Q_COMPILER_UNICODE_STRING has been revoked due
+// to lacking stdlib support. But QStringLiteral only needs the
+// core language feature, so just use u"" here unconditionally:
-#define QT_NO_UNICODE_LITERAL
-typedef ushort qunicodechar;
+#define QT_UNICODE_LITERAL_II(str) u"" str
+typedef char16_t qunicodechar;
#endif
Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
"qunicodechar must typedef an integral type of size 2");
-#ifndef QT_NO_UNICODE_LITERAL
-# define QT_UNICODE_LITERAL(str) QT_UNICODE_LITERAL_II(str)
-# if defined(Q_COMPILER_LAMBDA)
-
-# define QStringLiteral(str) \
- ([]() -> QString { \
+#define QT_UNICODE_LITERAL(str) QT_UNICODE_LITERAL_II(str)
+#define QStringLiteral(str) \
+ ([]() Q_DECL_NOEXCEPT -> QString { \
enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \
static const QStaticStringData<Size> qstring_literal = { \
Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \
@@ -190,17 +186,6 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
}()) \
/**/
-# endif
-#endif // QT_NO_UNICODE_LITERAL
-
-#ifndef QStringLiteral
-// no lambdas, not GCC, or GCC in C++98 mode with 4-byte wchar_t
-// fallback, return a temporary QString
-// source code is assumed to be encoded in UTF-8
-
-# define QStringLiteral(str) QString::fromUtf8("" str "", sizeof(str) - 1)
-#endif
-
#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \
{ Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \
/**/
@@ -535,9 +520,9 @@ public:
QByteArray toUtf8() && Q_REQUIRED_RESULT
{ return toUtf8_helper(*this); }
QByteArray toLocal8Bit() const & Q_REQUIRED_RESULT
- { return toLocal8Bit_helper(constData(), size()); }
+ { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); }
QByteArray toLocal8Bit() && Q_REQUIRED_RESULT
- { return toLocal8Bit_helper(constData(), size()); }
+ { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); }
#else
QByteArray toLatin1() const Q_REQUIRED_RESULT;
QByteArray toUtf8() const Q_REQUIRED_RESULT;