Deprecate QStringViewLiteral

As a macro, we can't directly deprecate it, but need to make it call
something deprecated. That is a new ctor with a new enum type
added. The type might be useful for other such ventures, so put it
into qglobal.h

Remove the QT_NO_UNICODE_LITERAL protection, as it's always false
these days, and QT_UNICODE_LITERAL is unconditionally #defined a 20
lines above.

[ChangeLog][QtCore][QStringView] Deprecated the (undocumented)
QStringViewLiteral macro. Just use u"" or QStringView(u"") instead.

Change-Id: I9141320225037e1bc6b7f920bf01a9d0144fdac2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Marc Mutz 2019-07-26 22:43:05 +03:00
parent b7d073e990
commit c58ca4256d
6 changed files with 28 additions and 16 deletions

View File

@ -248,7 +248,7 @@ static const char *encodingToolTips[]
{ {
QT_TRANSLATE_NOOP("EncodingDialog", "Unicode points for use with any encoding (C++, Python)"), QT_TRANSLATE_NOOP("EncodingDialog", "Unicode points for use with any encoding (C++, Python)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QString::fromUtf8()"), QT_TRANSLATE_NOOP("EncodingDialog", "QString::fromUtf8()"),
QT_TRANSLATE_NOOP("EncodingDialog", "QStringViewLiteral(), wchar_t on Windows"), QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Windows, char16_t everywhere"),
QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Unix (Ucs4)"), QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Unix (Ucs4)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QLatin1String") QT_TRANSLATE_NOOP("EncodingDialog", "QLatin1String")
}; };

View File

@ -382,6 +382,14 @@ typedef double qreal;
#define QT_DEPRECATED_VERSION_5(minor) QT_DEPRECATED_VERSION_5_##minor #define QT_DEPRECATED_VERSION_5(minor) QT_DEPRECATED_VERSION_5_##minor
#define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major(minor) #define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major(minor)
#ifdef __cplusplus
// A tag to help mark stuff deprecated (cf. QStringViewLiteral)
namespace QtPrivate {
enum class Deprecated_t {};
constexpr Q_DECL_UNUSED Deprecated_t Deprecated = {};
}
#endif
/* /*
The Qt modules' export macros. The Qt modules' export macros.
The options are: The options are:

View File

@ -82,11 +82,8 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QStringData)) \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QStringData)) \
/**/ /**/
#ifndef QT_NO_UNICODE_LITERAL #if QT_DEPRECATED_SINCE(5, 14)
# ifndef QT_UNICODE_LITERAL # define QStringViewLiteral(str) QStringView(QT_UNICODE_LITERAL(str), QtPrivate::Deprecated)
# error "If you change QStringLiteral, please change QStringViewLiteral, too"
# endif
# define QStringViewLiteral(str) QStringView(QT_UNICODE_LITERAL(str))
#endif #endif
template <int N> template <int N>

View File

@ -185,6 +185,13 @@ public:
template <typename Char> template <typename Char>
Q_DECL_CONSTEXPR QStringView(const Char *str) noexcept; Q_DECL_CONSTEXPR QStringView(const Char *str) noexcept;
#else #else
#if QT_DEPRECATED_SINCE(5, 14)
template <typename Array, if_compatible_array<Array> = true>
QT_DEPRECATED_VERSION_X_5_14(R"(Use u"~~~" or QStringView(u"~~~") instead of QStringViewLiteral("~~~"))")
Q_DECL_CONSTEXPR QStringView(const Array &str, QtPrivate::Deprecated_t) noexcept
: QStringView(str, lengthHelperArray(str)) {}
#endif // QT_DEPRECATED_SINCE
template <typename Array, if_compatible_array<Array> = true> template <typename Array, if_compatible_array<Array> = true>
Q_DECL_CONSTEXPR QStringView(const Array &str) noexcept Q_DECL_CONSTEXPR QStringView(const Array &str) noexcept
: QStringView(str, lengthHelperArray(str)) {} : QStringView(str, lengthHelperArray(str)) {}

View File

@ -70,7 +70,7 @@ void tst_QLatin1String::arg() const
do { \ do { \
auto p = QLatin1String(pattern); \ auto p = QLatin1String(pattern); \
QCOMPARE(p.arg(QLatin1String(arg1)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1)), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1)), expected); \ QCOMPARE(p.arg(u"" arg1), expected); \
QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \ QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \
QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \ QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \
} while (false) \ } while (false) \
@ -79,9 +79,9 @@ void tst_QLatin1String::arg() const
do { \ do { \
auto p = QLatin1String(pattern); \ auto p = QLatin1String(pattern); \
QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1), QLatin1String(arg2)), expected); \ QCOMPARE(p.arg(u"" arg1, QLatin1String(arg2)), expected); \
QCOMPARE(p.arg(QLatin1String(arg1), QStringViewLiteral(arg2)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1), u"" arg2), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1), QStringViewLiteral(arg2)), expected); \ QCOMPARE(p.arg(u"" arg1, u"" arg2), expected); \
} while (false) \ } while (false) \
/*end*/ /*end*/

View File

@ -431,20 +431,20 @@ void tst_QStringView::arg() const
{ {
#define CHECK1(pattern, arg1, expected) \ #define CHECK1(pattern, arg1, expected) \
do { \ do { \
auto p = QStringViewLiteral(pattern); \ auto p = QStringView(u"" pattern); \
QCOMPARE(p.arg(QLatin1String(arg1)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1)), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1)), expected); \ QCOMPARE(p.arg(u"" arg1), expected); \
QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \ QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \
QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \ QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \
} while (false) \ } while (false) \
/*end*/ /*end*/
#define CHECK2(pattern, arg1, arg2, expected) \ #define CHECK2(pattern, arg1, arg2, expected) \
do { \ do { \
auto p = QStringViewLiteral(pattern); \ auto p = QStringView(u"" pattern); \
QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1), QLatin1String(arg2)), expected); \ QCOMPARE(p.arg(u"" arg1, QLatin1String(arg2)), expected); \
QCOMPARE(p.arg(QLatin1String(arg1), QStringViewLiteral(arg2)), expected); \ QCOMPARE(p.arg(QLatin1String(arg1), u"" arg2), expected); \
QCOMPARE(p.arg(QStringViewLiteral(arg1), QStringViewLiteral(arg2)), expected); \ QCOMPARE(p.arg(u"" arg1, u"" arg2), expected); \
} while (false) \ } while (false) \
/*end*/ /*end*/