summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-08-04 10:11:55 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-05 04:33:49 +0000
commit6f18bd3b8c0445b670dd5ccc02e018c9260fba94 (patch)
tree41f2815f47449e5e44bd314d399330138562b8c5 /src/corelib/text
parenteaf68f386225b4869861039534c55cb66604be37 (diff)
QStringLiteral: suppress the clang-tidy warning about const_cast
We can't add the comment inside the macro, so we solve the problem by adding an extra level of indirection. Change-Id: Ib8fbfcfeb48a49ca945dfffd169829b3610f6a34 Reviewed-by: Rui Oliveira Reviewed-by: Marc Mutz <marc.mutz@kdab.com> (cherry picked from commit ae0b080c019025c2a949cf9468294ecf2b4eacb1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qstringliteral.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/corelib/text/qstringliteral.h b/src/corelib/text/qstringliteral.h
index d86e6eafd9..d9804b31d6 100644
--- a/src/corelib/text/qstringliteral.h
+++ b/src/corelib/text/qstringliteral.h
@@ -56,13 +56,23 @@ QT_BEGIN_NAMESPACE
// core language feature, so just use u"" here unconditionally:
#define QT_UNICODE_LITERAL(str) u"" str
+
+using QStringPrivate = QArrayDataPointer<char16_t>;
+
+namespace QtPrivate {
+template <qsizetype N>
+static Q_ALWAYS_INLINE QStringPrivate qMakeStringPrivate(const char16_t (&literal)[N])
+{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
+ auto str = const_cast<char16_t *>(literal);
+ return { nullptr, str, N - 1 };
+}
+}
+
#define QStringLiteral(str) \
- (QString(QStringPrivate(nullptr, \
- const_cast<char16_t *>(QT_UNICODE_LITERAL(str)), \
- sizeof(QT_UNICODE_LITERAL(str))/2 - 1))) \
+ (QString(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) \
/**/
-using QStringPrivate = QArrayDataPointer<char16_t>;
QT_END_NAMESPACE